这很混乱
我有一个UITableView,它更新和工作正常,直到它获得超过16个项目,然后当尝试终止更新后调用insertRowsAtIndexPaths崩溃.
正在添加的NSIndexPath都是有效的. -numberOfRowsInSection返回正确的数字.它不是抛出与数据集相关的错误,而是与其崩溃
*** Terminating app due to uncaught exception ‘NSInvalidArgumentException’,reason: ‘*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil’
当在tableView上调用endUpdates时.
数据源全部存在,NSIndexPaths很好.该代码在0到16行之间工作正常,但是当我添加第17个时,它会崩溃.另外,如果我启动它22项,它的工作正常,当我添加23rd它崩溃…如果我调用重新加载数据,而不是进行更新和插入过程它的工作正常,所以这与数据本身无关,和它不应该与我如何插入行,因为它工作通过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供参考.