ios - 无法在 iOS 6 中加载 UITableViewCell Nib

标签 ios uitableview

所以我不确定这里发生了什么,但在 iOS 6 之前,使用 Storyboard,我会这样做来创建一个 UITableViewCell 子类。

1) UITableViewCell 子类 .h 和 .m 为我的商店创建。 2) 在 Storyboard的 ViewController 上创建的自定义 UITableViewCell。将其标识更改为自定义 UITableViewCell。给它重用标识符名称。

然后当我想实例化单元格时,在 ViewController 的类中,在

static NSString *TotalDistanceCellIdentifier = @"TotalDistanceCellIdentifier";

在viewDidLoad中:

[self.tableView registerNib:[UINib nibWithNibName:@"TotalDistanceTableViewCell" bundle:nil] forCellReuseIdentifier:TotalDistanceCellIdentifier];

然后在 cellForRowAtIndexPath 中:

    TotalDistanceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TotalDistanceCellIdentifier];

    return cell;

在 iOS 5 和 5.1 中,我看到了我的 UITableViewCell。但是在我运行 iOS 6 的 iPhone 或 iOS 6 模拟器上,它崩溃了:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle:.....with name 'TotalDistanceTableViewCell''

iOS 6 中的 UItableViewCells 有什么变化吗?谢谢!

最佳答案

您描述的方式从来都不正确。如果它以前有效,则可能是异常是新的。

只有当您有一个单独的 nib 文件时,您才可以注册一个 nib。对于 Storyboard 中的原型(prototype),只需使用重用标识符出列,tableView 就会根据您的原型(prototype)创建新的单元格。

只需删除 registerNib 行,就可以了。

关于ios - 无法在 iOS 6 中加载 UITableViewCell Nib ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12890114/

相关文章:

ios - FBFriendPickerViewController 中的自定义 UITable

ios - 向后滑动失败时,SwiftUI 导航栏项目变得困惑

ios - 使用 SpriteKit 设置地面节点?

iOS swift JSON 到类对象

ios - 如何向右滑动隐藏 UITableView 中的删除按钮?

ios - iPhone X 上的 UITableViewCell ImageView 太大

ios - 显示不同高度的 UIWebView 和 UITableView

ios - 在 iOS 中滚动 TableView 时保留 Tableview 单元格值

ios - 检测 iOS 应用程序是通过应用程序切换器还是从主屏幕恢复的?

ios - 在 Tableview 标题中找到 UIButton 并更改按钮标题