Jestem trochę nowy w rozwoju Objective-C i iPhone'a i natknąłem się na problem podczas próby wyśrodkowania tekstu w komórce tabeli. Szukałem google, ale rozwiązania są dla starego błędu SDK, który został naprawiony, a te nie działają dla mnie.Wyśrodkuj Wyrównaj tekst w problemie UITableViewCell
Niektóre kodu:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = @"Please center me";
cell.textLabel.textAlignment = UITextAlignmentCenter;
return cell;
}
Powyższe nie wyśrodkować tekst.
Próbowałem również metodę willDisplayCell:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.textLabel.textAlignment = UITextAlignmentCenter;
}
a próbowałem kilka starych zamieszczonych rozwiązań:
UILabel* label = [[[cell contentView] subviews] objectAtIndex:0];
label.textAlignment = UITextAlignmentCenter;
return cell;
Żaden z nich nie ma żadnego wpływu na wyrównanie tekstu. Nie mam pojęcia, że jakakolwiek pomoc byłaby najbardziej ceniona.
Wiwaty z góry.
UITextAlignment jest przestarzałe w iOS 6.0, to teraz NSTextAlignment – Souljacker