【发布时间】:2015-11-21 18:52:27
【问题描述】:
在 ios 模拟器 9.1 或 9.0 上运行我的应用程序时,单元格为空白且 xcode 未显示错误。在 8.4 模拟器上运行良好。代码没有变化。
我已经尝试了以下
- 删除情节提要中的自定义单元格并重新创建它。没用
- 更改了标识符和文件名。没用
- 从项目中删除了自定义单元 .h 文件,然后将其添加回来。没用
- tableView 可见后执行reloadData。没用。
- 断开连接,然后重新连接情节提要中的 tableView 委托和数据源。没用。
- 在我的自定义单元格中使用了默认的
customCell.textLabel.text = [_nameArray objectAtIndex:indexPath.section];和 imageViewcustomCell.imageView.image = [_profileImageArray objectAtIndex:indexPath.section];属性。有效,但这无济于事,因为我想使用我的自定义对象。 - 硬编码 customName、customTime 和 customImage。
customCell.customName.text =@"hi";和customCell.customImage.image = [UIImage imageNamed:@"commentButton.png"];。没用 - 我在数据源方法中添加了断点并执行了所有断点。
- 我使用 NSLog 来查看我的 customCell 是否为 nil。我从日志
<messagePreviewCell: 0x7fcdf8dd3860; ...>收到以下回复。 - 在 cellForRowAtIndexPath 中设置值之前,我 NSLog 了 nameLabel,它记录了情节提要中设置的内容。
- 我在我的代码/情节提要中搜索隐藏命令,没有设置为隐藏。
选中“使用大小类”复选框,我已将大小设置为“wCompact hAny”。
在 viewcontroller.m 中找到的 cellForRowAtIndexPath 的代码
static NSString *simpleTableIdentifier = @"messagePreviewCell";
messagePreviewCell *customCell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
customCell.customName.text = [_nameArray objectAtIndex:indexPath.section];
customCell.customTime.text = [_timeArray objectAtIndex:indexPath.section];
customCell.customDescription.text = [_messageArray objectAtIndex:indexPath.section];
NSString *className = [[[_profileImageArray objectAtIndex:indexPath.section] class] description];
if ([className isEqualToString:@"UIImage"]) {
customCell.customImage.image = [_profileImageArray objectAtIndex:indexPath.section];
}
return customCell;
我的代码运行良好...请帮忙,谢谢!
【问题讨论】:
-
如果您对标签文本进行硬编码,单元格仍为空?例如:
customCell.customName.text = @"HELLOOO"; -
检查您的数据源//_nameArray 或 _timeArray.. 对标签进行硬编码
-
您是否将故事板中的 customName/customType/customDescription 标签连接(创建 IBOutlets)到您的代码?
-
此时要做的一件好事可能是在一些数据源方法中添加断点。然后检查: 1. 他们是否被叫到。 2. 你要出列的单元格是 nil。 3. 你的
nameArray、timeArray和messageArray是零吗? 4. 单元格上的标签是否为零。 5. 单元格上的任何内容是否通过 opacity 或 hidden 属性隐藏。 -
你在使用尺码等级吗?
标签: ios objective-c xcode uitableview