gpt4 book ai didi

ios - UITableViewController 由于单元格标识符而崩溃

转载 作者:行者123 更新时间:2023-11-28 20:03:22 24 4
gpt4 key购买 nike

我正在尝试加载 UITableViewController,但我不断收到此错误并且我的应用程序崩溃了。

* -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] 断言失败,/SourceCache/UIKit_Sim/UIKit-2935.137/UITableView.m:54392014-04-15 00:40:55.244 TradingGame[966:60b]* 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法使具有标识符单元格的单元格出列 - 必须注册 Nib 或类用于标识符或连接 Storyboard中的原型(prototype)单元格”

这是我的代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

if (cell) {
// will eventually put labels etc here.
}
return cell;

Image showing that i set the identifier

这是我调用 UITableViewController 推送到屏幕的地方:

    if (indexPath.row == 1) {
Foo *foo = [[Foo alloc] init];
[self.navigationController pushViewController:foo animated:YES];
}

最佳答案

问题解决了。感谢 @Paulw11 指出有关实例化 TableView 的信息。那些与我有类似问题的人对您的 tableview 实例化进行以下更改:先试试这个:

Foo *foo = [[Foo alloc] init];
[self.navigationController pushViewController:foo animated:YES];

如果这不起作用,您可能遇到与我类似的问题,因此请使用此代码:

Foo *foo = [self.storyboard instantiateViewControllerWithIdentifier:@"Foo"];
[self.navigationController pushViewController:foo animated:YES];

在适用的地方替换类,“Foo”应该等于您尝试实例化的 View Controller 的 Storyboard ID。

关于ios - UITableViewController 由于单元格标识符而崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23072442/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com