【发布时间】:2017-01-11 05:27:11
【问题描述】:
我有聊天应用程序,我从服务器获取历史记录并逐条获取消息,因此我获取一条消息并将其添加到数组并将行插入表中......这个过程非常快。
这里是代码:
-(void)msgRecevied:(NSMutableDictionary *)messageContent
{
if([chatWithUser isEqualToString:[messageContent objectForKey:kReceiver_User]])
return;
NSString *m = [messageContent objectForKey:kMsg];
[messageContent setObject:[m substituteEmoticons] forKey:kMsg];
[messageContent setObject:[messageContent objectForKey:kTrnDate] forKey:kTrnDate];
[messageContent setObject:[messageContent objectForKey:kSender_User] forKey:kSender_User];
[messageContent setObject:[messageContent objectForKey:kReceiver_User] forKey:kReceiver_User];
NSMutableDictionary *arrayTemp1 = [messageContent mutableCopy];
dispatch_async(dispatch_get_main_queue(), ^{
[app.Glb.arrayChat addObject:arrayTemp1];
numberOfRows = app.Glb.arrayChat.count;
if([app.Glb.arrayChat count] > 0)
{
[self.tblChatting beginUpdates];
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:[app.Glb.arrayChat count]-1 inSection:0];
[self.tblChatting insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationNone];
[self.tblChatting endUpdates];
[self.tblChatting scrollToRowAtIndexPath:newIndexPath
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];
newIndexPath = nil;
}
});
}
但我对endUpdates 崩溃了:
2016-09-03 10:47:32.638 [313:50270] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(0x2379f98b 0x22f3ae17 0x236b4e1f 0x2804372b 0x27d43a19 0x27d5aaa3 0x27f1a741 0x27efe987 0x7e93b 0x7a7b7f 0x7a7b6b 0x7ac655 0x23761bdd 0x237600d7 0x236af2e9 0x236af0d5 0x24c9fac9 0x27d740b9 0x39424d 0x23357873)
libc++abi.dylib: terminating with uncaught exception of type NSException
【问题讨论】:
-
首先检查您的应用程序崩溃的位置。 -[__NSArrayM insertObject:atIndex:]: object cannot be nil 建议您在 Mutable Array 中插入 nil。
-
但我没有在课堂上使用 insertObject:
标签: ios objective-c uitableview xmpp openfire