gpt4 book ai didi

ios - 怎么可能tableView :commitEditingStyle:forRowAtIndexPath: be called with a nil indexPath?

转载 作者:技术小花猫 更新时间:2023-10-29 10:54:19 28 4
gpt4 key购买 nike

我终于找到了一个奇怪的崩溃。这是由 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

最佳答案

异常是由于索引处存在数据但索引路径已被删除。您需要删除索引处的数组对象。

尝试以下操作:

- (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];
}
}

关于ios - 怎么可能tableView :commitEditingStyle:forRowAtIndexPath: be called with a nil indexPath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13167353/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com