Center Align text in UITableViewCell problem(UITableViewCell中的文本居中对齐问题)
问题描述
我对 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中的文本居中对齐问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UITableViewCell中的文本居中对齐问题


基础教程推荐
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01