通常,如果我重新加载表,它不会崩溃。但是,当我在后台获取一些数据然后重新加载表格以显示该数据时,同时如果用户正在滚动表格,则应用程序崩溃。原因是对象数组chatData
为空。我不明白它是怎么空的。因为就在重新加载表之前,我将对象设置为chatData
. 请注意,仅当用户同时滚动时才会崩溃。
- (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];
}
}