我对Objective-C和iPhone的开发颇为陌生,在尝试将表格中的文本居中时遇到了问题。我搜索谷歌,但解决方案是一个旧的SDK错误,已修复,这些不适合我。居中对齐UITableViewCell问题中的文本
一些代码:
- (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;
}
以上不居中的文本。
我也曾尝试willDisplayCell方法:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.textLabel.textAlignment = UITextAlignmentCenter;
}
,我已经尝试了一些旧发布的解决方案:
UILabel* label = [[[cell contentView] subviews] objectAtIndex:0];
label.textAlignment = UITextAlignmentCenter;
return cell;
这些都不对文本对齐任何影响。我已经用完了想法的任何帮助,将不胜感激。
提前欢呼。
UITextAlignment中的iOS 6.0过时了,它现在是NSTextAlignment – Souljacker 2012-10-19 09:05:27