调试运行时错误:"NSInternalInconsistencyException",理由是:"数据源的UITableView必须的tableView返回细胞:的cellForRowAtIndexPath"

Bil*_*ill 0 cocoa objective-c

我正在阅读"开始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: (
 ...
)
Run Code Online (Sandbox Code Playgroud)

我不是在寻求这本书的帮助,而是关于如何调试此错误的提示.我能确定哪种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;
}
Run Code Online (Sandbox Code Playgroud)

-

- (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;
}
Run Code Online (Sandbox Code Playgroud)

Ale*_*lds 5

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

cell == [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:RootViewControllerCell] autorelease];
Run Code Online (Sandbox Code Playgroud)

应该:

cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:RootViewControllerCell] autorelease];
Run Code Online (Sandbox Code Playgroud)