gpt4 book ai didi

objective-c - 调试运行时错误: 'NSInternalInconsistencyException' ,原因: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath'

转载 作者:行者123 更新时间:2023-12-03 17:29:48 25 4
gpt4 key购买 nike

我正在阅读《iPhone 开发入门》一书,但一直停留在第 9 章。我花了几个小时尝试调试此错误,但没有成功:

2010-05-01 19:27:51.361 Nav2[4113:20b] *** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit/UIKit-984.38/UITableView.m:4709
2010-05-01 19:27:51.362 Nav2[4113:20b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
2010-05-01 19:27:51.364 Nav2[4113:20b] Stack: (
...
)

我不是在寻求有关本书的帮助,而是寻求有关如何调试此错误的提示。我可以确定我的哪个 cellForRowAtIndexPath 方法有问题吗?以及如何检查类型?或者我应该看看其他什么?

编辑:根据要求,两个可疑方法的代码:

-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *RootViewControllerCell = @"RootViewControllerCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:RootViewControllerCell];
if (cell == nil) {
cell == [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:RootViewControllerCell] autorelease];
}

NSUInteger row = [indexPath row];
SecondLevelViewController *controller = [controllers objectAtIndex:row];
cell.textLabel.text = controller.title;
cell.image = controller.rowImage;
return cell;
}

--

- (UITableViewCell *)tableView:(UITableView *)tableView 
cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString * DisclosureButtonCellIdentifier =
@"DisclosureButtonCellIdentifier";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
DisclosureButtonCellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier: DisclosureButtonCellIdentifier]
autorelease];
}
return cell;

NSUInteger row = [indexPath row];
NSString *rowString = [list objectAtIndex:row];
cell.textLabel.text = rowString;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
[rowString release];
return cell;
}

最佳答案

您有一个额外的等号,即:

cell == [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:RootViewControllerCell] autorelease];

应该是:

cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:RootViewControllerCell] autorelease];

关于objective-c - 调试运行时错误: 'NSInternalInconsistencyException' ,原因: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2752294/

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