我对 Objective-C 和 iPhone 开发有点陌生,在尝试将文本置于表格单元格中时遇到了问题.我搜索了谷歌,但解决方案是针对已修复的旧 SDK 错误,这些对我不起作用.
I'm kinda new to Objective-C and iPhone development and I've come across a problem when trying to center the text in a table cell. I've searched google but the solutions are for an old SDK bug that has been fixed and these don't work for me.
一些代码:
- (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 方法:
I have also tried the willDisplayCell method:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.textLabel.textAlignment = UITextAlignmentCenter;
}
我已经尝试了一些旧发布的解决方案:
and I've tried some of the old posted solutions:
UILabel* label = [[[cell contentView] subviews] objectAtIndex:0];
label.textAlignment = UITextAlignmentCenter;
return cell;
这些都不会对文本对齐产生任何影响.我的想法已经用完了,任何帮助将不胜感激.
None of these have any effect on the text alignment. I have run out of idea's any help would be most appreciated.
提前干杯.
不知道它是否对你的具体问题有帮助,但是如果你使用 initWithStyle:UITableViewCellStyleDefault
确实可以工作代码>
Don't know if it helps your specific problem, however UITextAlignmentCenter
does work if you use initWithStyle:UITableViewCellStyleDefault
这篇关于UITableViewCell中的文本居中对齐问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!