带编辑表的SIGABRT-IOS
我有以下代码:带编辑表的SIGABRT-IOS,ios,uitableview,sigabrt,Ios,Uitableview,Sigabrt,我有以下代码: - (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { [self.tableView deleteRowsAtI
- (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
[[delegate contentArray] removeObjectAtIndex:indexPath.row];
[self.tableView reloadData];
}
if (editingStyle == UITableViewCellEditingStyleInsert) {
}
}
现在,当我运行它时,编辑按钮工作,删除界面出现,但当我按下删除按钮时,我得到一个SIGABRT错误
我还不知道如何读取日志文件,但是如果您需要它们,请告诉我如何将它们发送给您:-)
编辑:
我已在此处发布控制台日志:
GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug 8 20:32:45 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 41600.
2011-12-15 14:35:31.932 OrderList[41600:b903] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1448.89/UITableView.m:995
2011-12-15 14:35:32.227 OrderList[41600:b903] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (4) must be equal to the number of rows contained in that section before the update (4), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted).'
*** Call stack at first throw:
(
0 CoreFoundation 0x00fd55a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x01129313 objc_exception_throw + 44
2 CoreFoundation 0x00f8def8 +[NSException raise:format:arguments:] + 136
3 Foundation 0x008173bb -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UIKit 0x00092e8b -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] + 8420
5 UIKit 0x00081cf8 -[UITableView deleteRowsAtIndexPaths:withRowAnimation:] + 56
6 OrderList 0x00002546 -[RootViewController tableView:commitEditingStyle:forRowAtIndexPath:] + 166
7 UIKit 0x0007f037 -[UITableView(UITableViewInternal) animateDeletionOfRowWithCell:] + 101
8 UIKit 0x000144fd -[UIApplication sendAction:to:from:forEvent:] + 119
9 UIKit 0x000a4799 -[UIControl sendAction:to:forEvent:] + 67
10 UIKit 0x000a6c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
11 UIKit 0x000a57d8 -[UIControl touchesEnded:withEvent:] + 458
12 UIKit 0x00038ded -[UIWindow _sendTouchesForEvent:] + 567
13 UIKit 0x00019c37 -[UIApplication sendEvent:] + 447
14 UIKit 0x0001ef2e _UIApplicationHandleEvent + 7576
15 GraphicsServices 0x00cd6992 PurpleEventCallback + 1550
16 CoreFoundation 0x00fb6944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
17 CoreFoundation 0x00f16cf7 __CFRunLoopDoSource1 + 215
18 CoreFoundation 0x00f13f83 __CFRunLoopRun + 979
19 CoreFoundation 0x00f13840 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x00f13761 CFRunLoopRunInMode + 97
21 GraphicsServices 0x00cd51c4 GSEventRunModal + 217
22 GraphicsServices 0x00cd5289 GSEventRun + 115
23 UIKit 0x00022c93 UIApplicationMain + 1160
24 OrderList 0x00001bcd main + 125
25 OrderList 0x00001b45 start + 53
)
terminate called throwing an exception(gdb)
--Jeff这是日志中的关键行:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (4) must be equal to the number of rows contained in that section before the update (4), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted).'
mattjgalloway对解决方案的看法是100%正确的。我希望他将此作为一个答案发布,这样他就可以获得积分。请发布Xcode控制台中的内容。很可能会抛出异常,该异常将显示在那里。我的猜测是,您需要将您所拥有的内容包装在
[self.tableView beginUpdates]
和[self.tableView endUpdates]
中删除行的位置,然后丢失[self.tableView reloadData]
。如果您在模拟器上运行此程序并使用XCode4,您应该看到调试控制台XCode菜单->视图->调试区域->活动控制台。看看它为什么和西格伯特一起坠毁。发布调试信息有助于我们查明问题的起因,而不是进行模糊的猜测。要从代码中猜测,您可能正在从不可变数组中删除对象(NSArray是不可变数组,NSMutableArray是可变数组)。[delegate contentArray]可能是不可变数组。这是你的应用程序可能崩溃的原因。为答案干杯-我会根据你的请求为他保留信用。