Iphone 从tableView中删除单元格

Iphone 从tableView中删除单元格,iphone,objective-c,Iphone,Objective C,我在viewController中添加了一个tableview(我希望这样)。 tableview的每个单元格都有一个segmentcontroller,当用户单击该单元格时,该单元格将删除/删除 我最终得到了一个异常,我不知道如何解决它 2012-01-23 15:35:26.729测试项目[21003:707]*断言失败 在-[UITableView\u endCellAnimationsWithContext:]中, /SourceCache/UIKit/UIKit-1448.89/UIT

我在viewController中添加了一个tableview(我希望这样)。 tableview的每个单元格都有一个segmentcontroller,当用户单击该单元格时,该单元格将删除/删除

我最终得到了一个异常,我不知道如何解决它

2012-01-23 15:35:26.729测试项目[21003:707]*断言失败 在-[UITableView\u endCellAnimationsWithContext:]中, /SourceCache/UIKit/UIKit-1448.89/UITableView.m:995

2012-01-23 15:35:26.761测试项目[21003:707]*终止应用程序 由于未捕获的异常“NSInternalInconsistencyException”,原因: '无效更新:节0中的行数无效。人数 更新(2)后现有节中包含的行必须是 等于该节中包含的行数,在 更新(2),加上或减去从中插入或删除的行数 该部分(插入0,删除1)。'

我的代码到目前为止

按钮事件中的

UITableViewCell *cell=(UITableViewCell *)segmentController.superview.superview;

        NSIndexPath *indexPath = [self.myTableView indexPathForCell:cell];

        Person *person= [[self allThdata] objectAtIndex:indexPath.row];

                [self.allThdata removeObjectIdenticalTo:person];

        [self.myTableView beginUpdates];

        [self.myTableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:YES];

        [self.myTableView endUpdates];

我还尝试了
removeObjectAtIndex:indexath.row
removeObject:person
。所有这些都不起作用

removeObjectAtIndex:
的调用应该在
BeginUpdate
块中

这应该可以做到:

UITableViewCell *cell=(UITableViewCell *)segmentController.superview.superview;
NSIndexPath *indexPath = [self.myTableView indexPathForCell:cell];
[self.myTableView beginUpdates];
[[self allThdata] removeObjectAtIndex:indexPath.row];
[self.myTableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:YES];
[self.myTableView endUpdates];

我想我已经试过了,但是
[[self-allThdata]removeObjectAtIndex:indexPath.row]行位于[self.myTableView beginUpdates]上方。它应该在下面
[self.myTableView beginUpdates]