【发布时间】:2012-10-21 11:11:48
【问题描述】:
我终于找到了一个奇怪的崩溃。这是由tableView:commitEditingStyle:forRowAtIndexPath: 被nil indexPath 调用引起的。但怎么可能呢?
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// DEBUG
if (indexPath == nil) {
NSLog(@"Deleting row at nil indexPath in %@", self);
}
[self deleteItemAtIndexPath:indexPath fromTableView:tableView];
}
}
这是堆栈跟踪:
6 XXX -[ListViewController tableView:commitEditingStyle:forRowAtIndexPath:] (ListViewController.m:427)
7 UIKit -[UITableView(UITableViewInternal) animateDeletionOfRowWithCell:] + 85
8 UIKit -[UIApplication sendAction:to:from:forEvent:] + 73
9 UIKit -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 31
10 UIKit -[UIControl sendAction:to:forEvent:] + 45
11 UIKit -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 503
12 UIKit -[UIApplication sendAction:to:from:forEvent:] + 73
13 UIKit -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 31
14 UIKit -[UIControl sendAction:to:forEvent:] + 45
15 UIKit -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 503
16 UIKit -[UIControl touchesEnded:withEvent:] + 489
17 UIKit -[UIWindow _sendTouchesForEvent:] + 525
18 UIKit -[UIApplication sendEvent:] + 381
19 UIKit _UIApplicationHandleEvent + 6155
20 GraphicsServices _PurpleEventCallback + 591
21 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
22 CoreFoundation __CFRunLoopDoSources0 + 213
23 CoreFoundation __CFRunLoopRun + 647
24 CoreFoundation CFRunLoopRunSpecific + 357
25 CoreFoundation CFRunLoopRunInMode + 105
26 GraphicsServices GSEventRunModal + 75
27 UIKit UIApplicationMain + 1121
28 XXX main (main.m:16)
29 XXX start + 40
【问题讨论】:
-
您有显示调用来源的堆栈跟踪吗?
-
我有同样的 IndexPath 错误,但有另一个堆栈跟踪。你解决了这个问题吗?
-
我已经在我的代码中解决了这个问题。我在 NSTimer 的处理程序中调用了 UITableView: reloadRowsAtIndexPaths:withRowAnimation:。有时这会导致 tableView:commitEditingStyle:forRowAtIndexPath: 崩溃。但我不明白崩溃是如何发生的,因为这两种方法都是在同一个线程中执行的。
-
在deleteItemAtIndexPath中,你是否在那个方法中做一些多线程?
标签: ios uitableview