Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 删除UITableView行问题_Iphone_Objective C_Cocoa Touch - Fatal编程技术网

Iphone 删除UITableView行问题

Iphone 删除UITableView行问题,iphone,objective-c,cocoa-touch,Iphone,Objective C,Cocoa Touch,我有一个问题,我看到很多人。。。然而,没有一个修复对我有效。但是当我在代码中加入NSLog命令时,我确实注意到了一些奇怪的事情 我有标准的删除方法: - (void) tableView: (UITableView *) tableView commitEditingStyle: (UITableViewCellEditingStyle) editingStyle forRowAtIndexPath: (NSIndexPath *) indexPath { if (editingSty

我有一个问题,我看到很多人。。。然而,没有一个修复对我有效。但是当我在代码中加入NSLog命令时,我确实注意到了一些奇怪的事情

我有标准的删除方法:

- (void) tableView: (UITableView *) tableView commitEditingStyle: (UITableViewCellEditingStyle) editingStyle forRowAtIndexPath: (NSIndexPath *) indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [self.recipes removeObjectAtIndex: indexPath.row];
        [tableView beginUpdates];
        [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject: indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [tableView endUpdates];

    }

}
recipes是保存数据源的数组

理论上,这应该很好,但我得到了一个错误:

invalid number of rows in section 1.  The number of rows contained in an existing section after the update (9) must be equal to the number of rows contained in that section before the update (10), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted).
但是我知道这是怎么回事,当我在numberOfRowsInSection中添加一个NSLog时,我看到这个方法被上面的方法调用了两次

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    NSLog(@"THIS CALLED TWICE  %i",[recipes count] );
    return [recipes count];
}
有人知道还有什么会导致numberOfRowsInSection方法触发两次吗


谢谢您的时间。

写了这篇文章后,我发现我有以下几点:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 2;
}
显然,每个部分都会调用numberOfRowsInSection。。。将代码更改为:

  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        // Return the number of sections.
        return 1;
    }
已修复此问题。

已删除标记“xcode”