在什么情况下,UITableView在-[UITableViewDelegate tableView:titleForDeleteConfirmationButtonForRowAtIndexPath:]中的行中给出-1或NSUIntegerMax?

下面是用户的崩溃日志。

OS Version:      iPhone OS 9.2.1 (13D15)

Application Specific Information:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'no object at index 18446744073709551615 in section at index 0'

Last Exception Backtrace:
0   CoreFoundation                      0x0000000181241900 __exceptionPreprocess + 124
1   libobjc.A.dylib                     0x00000001808aff80 objc_exception_throw + 56
2   CoreData                            0x0000000182cc50bc -[NSFetchedResultsController objectAtIndexPath:] + 456
3   My App                              0x000000010022c678 -[MyViewController tableView:titleForDeleteConfirmationButtonForRowAtIndexPath:] (MyViewController.m:560)
4   UIKit                               0x0000000186145174 -[UITableView _titleForDeleteConfirmationButtonForRowAtIndexPath:] + 160
5   UIKit                               0x00000001862756f4 -[UITableView _deleteConfirmationButtonForRowAtIndexPath:] + 116
6   UIKit                               0x0000000186275cf4 -[UITableView _swipeActionButtonsForRowAtIndexPath:] + 824
7   UIKit                               0x0000000186275998 -[UITableView _swipeActionButtons] + 92
8   UIKit                               0x0000000186144bd8 __32-[UITableViewCell _beginSwiping]_block_invoke + 120
9   UIKit                               0x0000000185f42964 +[UIView(Animation) performWithoutAnimation:] + 80
10  UIKit                               0x0000000186144b48 -[UITableViewCell _beginSwiping] + 96
11  UIKit                               0x0000000186272320 -[UITableViewWrapperView handleSwipeBeginning:] + 256
12  UIKit                               0x00000001864b4ea4 _UIGestureRecognizerSendTargetActions + 396
13  UIKit                               0x00000001860d85b8 _UIGestureRecognizerSendActions + 172
14  UIKit                               0x0000000185f669b0 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 784
15  UIKit                               0x00000001864b63bc ___UIGestureRecognizerUpdate_block_invoke904 + 72
16  UIKit                               0x0000000185f25b58 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 372
17  UIKit                               0x0000000185f228dc _UIGestureRecognizerUpdate + 2404
18  UIKit                               0x0000000185f64820 -[UIWindow _sendGesturesForEvent:] + 1132
19  UIKit                               0x0000000185f63e1c -[UIWindow sendEvent:] + 764
20  UIKit                               0x0000000185f344cc -[UIApplication sendEvent:] + 248
21  UIKit                               0x0000000185f32794 _UIApplicationHandleEventQueue + 5528
22  CoreFoundation                      0x00000001811f8efc __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
23  CoreFoundation                      0x00000001811f8990 __CFRunLoopDoSources0 + 540
24  CoreFoundation                      0x00000001811f6690 __CFRunLoopRun + 724
25  CoreFoundation                      0x0000000181125680 CFRunLoopRunSpecific + 384
26  GraphicsServices                    0x0000000182634088 GSEventRunModal + 180
27  UIKit                               0x0000000185f9cd90 UIApplicationMain + 204
28  My App                              0x00000001000a926c main (main.m:16)
29  ???                                 0x0000000180cc68b8 0x0 + 0
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyMessage *message = [self messageAtIndex:indexPath.row];
    if ([message.senderUid isEqualToString:mUid])
        return NSLocalizedString(@"Delete", nil);
    else
        return NSLocalizedString(@"Hide", nil);
}

- (MyMessage *)messageAtIndex:(NSInteger)index
{
    return [mMessagesController objectAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0]];
}

最佳答案

indexPath.rowindexPath.section都是NSUInteger(无符号整数),这意味着它严格是正数。如果减去并最终变为负数,它将跳至NSUIntegerMax。这使得必须小心涉及索引路径的算法。

当对等于零的row - 1执行row时,将获得NSUIntegerMax

关于ios - -[UITableViewDelegate tableView:titleForDeleteConfirmationButtonForRowAtIndexPath:]给定的第-1行或NSUIntegerMax,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36546037/

10-08 20:36