tableView最终导致超过16个项目崩溃

 DZ2017 发布于 2023-02-10 12:45

这非常令人困惑.

我有一个UITableView,它更新并且工作正常,直到它获得超过16个项目然后它在尝试endUpdates调用后崩溃insertRowsAtIndexPaths.

NSIndexPath添加的s都是有效的.-numberOfRowsInSection返回正确的数字.它不会抛出与数据集相关的错误,而是会崩溃

***由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:'*** - [__ NSArrayM insertObject:atIndex:]:object不能为nil'

什么时候endUpdates打电话给tableView.

数据源都在那里,NSIndexPaths很好.代码在0到16行之间正常工作,但是当我添加第17行时它会崩溃.另外如果我用22个项目启动它可以正常工作,当我添加第23个它崩溃时...如果我调用重载数据而不是执行更新和插入过程它工作正常,所以它与数据本身无关,并且它不应该与我如何插入行有关,因为它通过16 ...

我完全感到困惑.这是我的更新方法.它始终在主线程上调用.

- (void)updateConversation:(NSNotification*)notification
{
    NSDictionary *updateInfo = [notification userInfo];
    //NSLog(@"Got update %@", updateInfo);

    if ([[updateInfo objectForKey:@"success"] integerValue] == YES) {
        [self updateConversationUI];

        int addedStatementCount = [[updateInfo objectForKey:@"addedStatementCount"] intValue];

        if (addedStatementCount > 0) {
            //[self.tableView reloadData];
            [self.tableView beginUpdates];
            int previousStatmentCount = [[updateInfo objectForKey:@"previousStatmentCount"] intValue];

            NSLog(@"owner %i, Was %i, now %i, change of %i", self.owner, previousStatmentCount, (int)self.conversation.statements.count, addedStatementCount);

            NSMutableArray *rowPaths = [[NSMutableArray alloc] init];

            for (int i = previousStatmentCount; i < previousStatmentCount + addedStatementCount; i++) {
                NSIndexPath *path = [NSIndexPath indexPathForRow:i inSection:0];
                [rowPaths addObject:path];
            }

            [self.tableView insertRowsAtIndexPaths:rowPaths withRowAnimation:UITableViewRowAnimationBottom];        
            [self.tableView endUpdates];
            [self.tableView scrollToRowAtIndexPath:[rowPaths lastObject] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
        }
    }
}

通过[self.tableView endUpdates]的其余崩溃是UITableView

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010189b795 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001015fe991 objc_exception_throw + 43
    2   CoreFoundation                      0x0000000101852564 -[__NSArrayM insertObject:atIndex:] + 820
    3   UIKit                               0x0000000100317900 __46-[UITableView _updateWithItems:updateSupport:]_block_invoke691 + 173
    4   UIKit                               0x00000001002b5daf +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 460
    5   UIKit                               0x00000001002b6004 +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:] + 57
    6   UIKit                               0x00000001003174cb -[UITableView _updateWithItems:updateSupport:] + 2632
    7   UIKit                               0x0000000100312b18 -[UITableView _endCellAnimationsWithContext:] + 11615
    8   Dev App                         0x0000000100006036 -[ConversationViewController updateConversation:] + 998
    9   CoreFoundation                      0x00000001018f121c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    10  CoreFoundation                      0x000000010185370d _CFXNotificationPost + 2381
    11  Dev App                         0x00000001000055ac -[ConversationManager postNotification:] + 92
    12  Foundation                          0x0000000101204557 __NSThreadPerformPerform + 227
    13  CoreFoundation                      0x000000010182aec1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    14  CoreFoundation                      0x000000010182a792 __CFRunLoopDoSources0 + 242
    15  CoreFoundation                      0x000000010184661f __CFRunLoopRun + 767
    16  CoreFoundation                      0x0000000101845f33 CFRunLoopRunSpecific + 467
    17  GraphicsServices                    0x00000001039a23a0 GSEventRunModal + 161
    18  UIKit                               0x0000000100261043 UIApplicationMain + 1010
    19  Dev App                         0x0000000100003613 main + 115
    20  libdyld.dylib                       0x0000000101f2a5fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

这似乎是操作系统中的一个错误,堆栈会表明它与动画块有关,但无论我将动画设置为什么,它都会发生,包括没有.

并重新陈述.这通过16个项目,然后插入过去的项目导致崩溃.它也在初始设置时被调用以加载数据,并且它将在那里加载任意数量的项目,包括16以上.但是当再次调用时,纯粹作为从16或更高的更新到更高的更新它将崩溃.

最奇怪的问题我还没有遇到过表格视图......

在iOS 7的设备和模拟器下,最新的Xcode供参考.

1 个回答
  • 似乎这个问题是由我调用scrollToRowAtIndexPath引起的(即使它在它到达之前它崩溃了......)结合实现tableView:estimatedHeightForRowAtIndexPath:通过删除行高估计崩溃消失......仍然看起来像一个bug在动画系统中为我提供表格.值得庆幸的是,我不需要估计行高,我已经忘记了我已经实现了它(尝试玩得很好,iOS 7再次咬我).

    2023-02-10 12:46 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有