- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
当我将 UIViewController 推送到我的 UINavigation Controller 时,如下所示:
[(UINavigationController *)self.parentViewController pushViewController:[[[Fonts alloc] initWithNibName:@"Fonts" bundle:nil] autorelease] animated:YES];
其中 Fonts.xib 是一个 UIView,只有 UITableView 由 Fonts 对象控制,该对象是 UIViewController 的子类,充当 UITableView 的数据源和委托(delegate)。
在 Fonts 对象中,我创建了一个 UITableViewCell,如下所示:
- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: @"BlahTableViewCell"];
if (!cell) {
cell = [[UITableViewCell alloc]
initWithStyle: UITableViewCellStyleDefault
reuseIdentifier: @"BlahTableViewCell"];
[cell autorelease]; // Delete for ARC
}
return cell;
}
然后我在这里更改单元格的字体:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[cell.textLabel setFont:[(UIFont *)[self.listOfFonts objectAtIndex:indexPath.row] fontWithSize:cell.textLabel.font.pointSize]];
cell.textLabel.text = [(UIFont *)[self.listOfFonts objectAtIndex:indexPath.row] fontName];
}
listOfFonts 是 UIFont 对象的 NSArray。
当 View 出现时,它看起来像 UITableView without changed fonts
如果我在 UITableView 上调用 reloadData,或者如果我用手指将 UITableViewCells 拖出屏幕并让它们弹回,它们将被重绘并且 View 中显示的单元格的字体已更改。
问题似乎是 UITableViewCells 绘制得太早了。如果我延迟绘制它们,一切看起来都是正确的,但我希望 UITableView 在 UINavigationController 将我的 View 滑动到位时正确显示。
知道我做错了什么吗?
编辑:我将我的问题的一个简单明了的示例上传到 Dropbox。 http://dl.dropbox.com/u/5535847/UITableViewIssue.zip
最佳答案
解决了!
好吧,我遇到了与原始海报完全相同的问题,这就是问题所在。
引起问题的行是:
[cell.textLabel setFont:[(UIFont *)[self.listOfFonts objectAtIndex:indexPath.row] fontWithSize:cell.textLabel.font.pointSize]];
具体来说,您的问题是因为您试图为单元格的 textLabel 提供它自己的 pointSize,但 pointSize 尚不存在,因此会出现奇怪的错误。对我来说,我注意到由于奇异矩阵不可逆,“变换”失败了。一旦我将标准值硬编码为我的 pointSize,我就会立即看到我所有的标签都使用正确的字体绘制。注意:关于为什么重绘有效,这是有道理的,因为那时你的 textLabel 确实有一个 pointSize。
在任何情况下,您都需要在此处明确设置您的 pointSize,不要使用 textLabel“已有”的内容,因为在您“重新加载”单元格之前它没有任何内容。
关于ios - UITableViewCell 的 textLabel 的字体变化没有视觉上的变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9135297/
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPa
当您使用 UITableViewCell 的内置样式(副标题、右侧细节等)时,您可以使用 textLabel 和 轻松访问文本标签>detailTextLabel 是 UITableViewCell
我是 iPhone 开发新手,目前正在开发一个简单的 RSS 阅读器应用程序。我遇到的问题是我需要重新定位 UITableViewCells 内的 textLabel 。我尝试过 setFrame 或
我希望在按下按钮时让文本标签淡入淡出。我注意到 textlabel 没有不透明度参数。还有其他方法可以达到预期的结果吗? 最佳答案 Winform 不支持Control 不透明度。 在 .Net Fr
好吧,我是一个初学者,我创建了一个带有自定义单元格类的 UITableView,该单元格类按其应有的方式加载,并在每个文本标签中显示 2 个文本标签(cellPrice 和 cellTitle)行/单
我有这个代码: cell.textLabel.text = [arrBugs objectAtIndex:indexPath.row]; cell.detailTextLabel.text = @"j
有一个 UITableViewCell“postCell”,它是一个 IBOutlet,并附加到我放置在 .xib 中的单元格。设置文本标签: - (void)viewDidAppear:(BOOL)
我是 IOS 开发的新手,现在我在 cell.textLabel.textColor 中遇到问题 我所做的是实现一个 TableView ,并根据部分设置颜色,如下所示,我有 4 个部分,每个部分有
我有一个一年前的项目成功了。 我已经编码了: cell.textLabel.numberOfLines = 0; // Multiline 在 UITableView 单元格中启用多行文本,之前它在
我在 swift 中使用部分以编程方式创建了一个 TableView。部分和行的数量将始终相同,因为它们只是显示我从 Firebase 提取的信息。 我想更改其中一个单元格的 textLabel 以对
我正在使用 Swiftforms,发现 here , 添加一个表单供用户填写。由于我已经掌握了大部分信息,因此我正在为用户填写表格,然后如果他们选择并单击提交,他们就可以对其进行编辑。当我预填文本时,
我有自定义 UITableViewCell,但无法在 cellForRow: atIndexPath: 中设置缩进。 cell.indentationWidth = 10.0 cell.indenta
我正在尝试将单元格的 textLabel 文本显示在跨越整个单元格的图像之上。我创建了一个自定义单元格子类,只是为了使图像宽度等于整个单元格大小,如下所示: - (void) layoutSubvi
我希望有一个带有一些标签的表格,然后我在标签后添加一个文本字段 UI。我希望标签的大小固定(例如 150),单元格宽度的其余部分由文本字段占据。 因此我在函数中设置了 cell.textLabel 的
我正在努力使我的 UITableViewCell 的文本标签中的文本从单元格的右侧环绕大约 30 个像素。然而,它从右边开始大约 5 或 10 个像素。我已经尝试编辑我在 cellForRowAtIn
有没有办法让 UIButton 在其 textLabel 中有两种不同的字体大小?原生? 我不想在顶部放置 UILabel。 最佳答案 您可以在界面生成器中执行此操作。此 GIF 将向您展示如何增加文
我有一个 UITableView,作为 cellForRowAtIndexPath 方法,我正在更改单元格的一些属性(字体、大小等)。现在,除了更改 textLabel 的颜色外,下面列出的所有分配都
我几乎尝试了所有方法,但似乎无法将 cell.textLabel 属性向下移动一点点。我在下面附上了一张截图,我已经尝试了几乎所有我能找到的东西。 我尝试直接更改 .frame 属性,尝试通过使用“-
我已经使用代码创建了一个 UITableView 和一个 UITableViewCell 的子类,在我选择单元格之前它显示得非常好。 单元格的textLabel有时会右移或不移 选择前问题的图像表示
我有一个可排序的 UITableView,但仅此而已。现在,我将所有单元格设置为 UITableViewCellEditingStyleNone,但这仍然将单元格的 TextLabel 向右移动 40
我是一名优秀的程序员,十分优秀!