Ios tableView:CommittedItingStyle:ForRowatineXpath:如何使用nil索引XPath调用?
我终于找到了一起奇怪的车祸。这是由使用Ios tableView:CommittedItingStyle:ForRowatineXpath:如何使用nil索引XPath调用?,ios,uitableview,Ios,Uitableview,我终于找到了一起奇怪的车祸。这是由使用nilindexath调用tableView:committeeditingstyle:forRowAtIndexPath:引起的。但这怎么可能呢 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (
nil
indexath调用tableView:committeeditingstyle:forRowAtIndexPath:
引起的。但这怎么可能呢
- (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已被删除。您需要删除索引处的数组对象 请尝试以下操作:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[self deleteItemAtIndexPath:indexPath fromTableView:tableView];
NSMutableArray * tempArray = [yourDataArray mutableCopy];
[tempArray removeObjectAtIndex: indexPath.row];
yourDataArray = tempArray;
[tableView reloadData];
}
}
您是否有一个堆栈跟踪显示调用来自何处?我有相同的IndexPath错误,但有另一个堆栈跟踪。你解决了这个问题吗?我已经在代码中解决了这个问题。我在NSTimer的处理程序中调用了UITableView:reloadRowsAtIndexPaths:withRowAnimation:。有时这会导致tableView:CommittedItingStyle:ForRowatineXpath:崩溃。但是我不明白崩溃是怎么发生的,因为这两个方法都在同一个线程中执行。在deleteItemAtIndexPath中,您是否在该方法中执行了一些多线程处理?