我是Objective-C和iPhone开发的新手,在try 将文本放在表格单元格的中心时遇到了一个问题.我搜索过谷歌,但解决方案是针对一个已经修复的老SDK错误,这些对我不起作用.
一些代码:
- (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;
}
上面的文字没有居中.
我也try 过willDisplayCell方法:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.textLabel.textAlignment = UITextAlignmentCenter;
}
我也try 过一些以前发布的解决方案:
UILabel* label = [[[cell contentView] subviews] objectAtIndex:0];
label.textAlignment = UITextAlignmentCenter;
return cell;
这些都不会对文本对齐产生任何影响.我的pip 用完了,非常感谢您的帮助.
提前欢呼.