通常,如果我重新加载表,它不会崩溃。但是,当我在后台获取一些数据,然后重新加载表以显示该数据,并且同时如果用户正在滚动表,则应用程序崩溃。原因是对象数组chatData
是空的。我不明白它是空的。因为在重新加载表之前,我将对象设置为chatData
。请注意,只有在用户同时滚动时才会崩溃。应用程序崩溃时重新加载tableView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Here app crashes when chatData is empty. Don't get why it is ever empty, because reloadData is called only after setting objects.
if ([user.userId isEqualToString:[[chatData objectAtIndex:row] objectForKey:SET_SENDER]])
{
}
}
- (void)refreshTable
{
.
.
.
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error)
{
self.chatData = [objects mutableCopy];
[chatTable reloadData];
}
}
numberOfRows的外观如何? – nhgrif
你应该在主线程中调用它,而不是在背景上。正如@andrew建议的那样。 – Pawan