tableView崩溃结束了超过16个项目 [英] tableView crashes on end up with more than 16 items

查看:770
本文介绍了tableView崩溃结束了超过16个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很混乱。

我有一个 UITableView ,更新和工作正常,直到它更多则在调用 insertRowsAtIndexPaths 后尝试 endUpdates 时会崩溃。

I have a UITableView, which updates and works fine until it gets more than 16 items then it crashes when trying to endUpdates after calling insertRowsAtIndexPaths.

正在添加的 NSIndexPath 都是有效的。 -numberOfRowsInSection 返回正确的数字。它不是与数据集相关的错误,而是与

The NSIndexPaths being added are all valid. -numberOfRowsInSection returns the correct number. It is not throwing an error related to the data set, rather it crashes with


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

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'

> c $>

表格上调用 endUpdates NSIndexPath 可以。代码在0和16行之间工作正常,但当我添加一个17的时候崩溃。此外,如果我启动它22个项目,它工作正常,当我添加23rd它崩溃...如果我调用重新加载数据,而不是做更新和插入过程,它工作正常,所以它与数据本身无关,它不应该与我插入的行,因为它工作通过16 ...任何事情...

when endUpdates is called on the tableView.

我完全感到困惑。这里是我的更新方法。

The data source is all there, the NSIndexPaths are fine. the code works fine between 0 and 16 rows, but when I add a 17th it crashes. Additionally if I start it with 22 items it works fine, when I add the 23rd it crashes... if I call reload data instead of doing the update and insert process it works fine, so it's nothing to do with the data itself, and it shouldn't be anything to do with how I'm inserting the rows since it works through 16...

I'm completely perplexed. Here is my update method. It is being called on the main thread at all times.
- (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] is UITableView

The rest of the crash past [self.tableView endUpdates] is 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

这似乎在操作系统中的一个错误,堆栈将表明它是与动画块,但它发生无论我设置的动画,包括无。

This seems like a bug in the OS, the stack would indicate that it's something to do with the animation block but it happens no matter what I set the animation to, including none.

并重新建立状态。这可以通过16个项目,然后插入项目,导致崩溃。它也在初始设置时调用以加载数据,并且它将加载任何数量的项目,包括大于16。但是当再次调用时,纯粹作为从16或更高到更高的更新将会崩溃。

And to re-state. This works through 16 items, then inserting items past that causes a crash. It is also called at initial setup to load data, and it will load any number of items there, including well over 16. But when called again, purely as an update from 16 or more to something higher it will crash.

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

Most bizarre issue I've yet to encounter with table views...

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

under iOS 7 on device and simulator, latest Xcode for reference.

推荐答案

看来这个问题是由我scrollToRowAtIndexPath(呼叫引起的,即使它崩溃,到达那里之前...)结合实现tableView:estimatedHeightForRowAtIndexPath:通过删除行高估计崩溃消失...仍然像动画系统中的一个错误为我的表。幸运的是,我不需要估计的行高,我已经忘记了我已经实现了(试图玩的漂亮的iOS 7咬我)。

It seems that the problem is caused by my call of scrollToRowAtIndexPath (even though it crashes before it gets there...) combined with implementing tableView:estimatedHeightForRowAtIndexPath: by removing the row height estimate the crash went away... still seems like a bug in the animation system for tables to me. Thankfully I don't need the estimated row height, I had forgotten I had implemented it (trying to play nice by iOS 7 bites me again).

这篇关于tableView崩溃结束了超过16个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆