【发布时间】:2011-06-02 22:47:48
【问题描述】:
我有一个使用单例对象作为数据源的 UITableView。
我已经实现了以下方法来允许用户删除 UITableView 中的行。但是当我单击删除按钮时,应用程序崩溃并出现异常
方法:
-(void)viewDidLoad
{
some initialization code-----
UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:@"Delete" style:UIBarButtonItemStyleBordered target:self action:@selector(toggleEdit:)];
self.navigationItem.rightBarButtonItem = editButton;
[editButton release];
}
-(IBAction)toggleEdit:(id)sender
{
[self.myOrderTable setEditing:!self.myOrderTable.editing animated:YES];
if(self.myOrderTable.editing)
[self.navigationItem.rightBarButtonItem setTitle:@"Done"];
else
{
[self.navigationItem.rightBarButtonItem setTitle:@"Delete"];
}
}
-(void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath
{
NSUInteger row = [indexPath row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
但是,当我尝试单击删除按钮时出现以下异常:
-[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1448.89/UITableView.m:995 中的断言失败
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无效更新:第 1 节中的行数无效。更新后现有节中包含的行数 (1) 必须等于行数更新前包含在该节中 (1),加上或减去从该节插入或删除的行数(0 插入,1 删除)。'
*** Call stack at first throw:
(
0 CoreFoundation 0x010305a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x01184313 objc_exception_throw + 44
2 CoreFoundation 0x00fe8ef8
+[NSException raise:format:arguments:] + 136
3 Foundation 0x001153bb -
[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UIKit 0x00398e8b -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] + 8420
5 UIKit 0x00387cf8 -
[UITableView deleteRowsAtIndexPaths:withRowAnimation:] + 56
6 Restaurant 0x000117f9 -
[MyOrderViewController tableView:commitEditingStyle:forRowAtIndexPath:] + 114
7 UIKit 0x00385037 -[UITableView(UITableViewInternal) animateDeletionOfRowWithCell:] + 101
8 UIKit 0x0031a4fd -[UIApplication sendAction:to:from:forEvent:] + 119
9 UIKit 0x003aa799 -[UIControl sendAction:to:forEvent:] + 67
10 UIKit 0x003acc2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
11 UIKit 0x003ab7d8 -[UIControl touchesEnded:withEvent:] + 458
.............
..........
.............
)
terminate called after throwing an instance of 'NSException'
我可以从哪里着手解决这个问题?
【问题讨论】:
标签: iphone uitableview