通常,如果我重新加載表,它不會崩潰。但是,當我在後臺獲取一些數據,然後重新加載表以顯示該數據,並且同時如果用戶正在滾動表,則應用程序崩潰。原因是對象數組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