在catch块内的UITableView reloadData

我想在UITableView中添加一个catch块,但它什么都不做。

[self.dataArray addObject:@"xyz"]; @try { [self.tableView beginUpdates]; //try with nil to go to catch block [self.tableView insertRowsAtIndexPaths:nil withRowAnimation:UITableViewRowAnimationBottom]; [self.tableView endUpdates]; } @catch (NSException * e) { dispatch_async(dispatch_get_main_queue(), ^{ [self.tableView reloadData]; }); } 

任何build议如何重新加载tableview的情况下更新失败的情况下? 谢谢!

更新

所以我可以处理,如果insertRowsAtIndexPaths:无这个工程

 @try { [self.tableView beginUpdates]; //try with nil to go to catch block [self.tableView insertRowsAtIndexPaths:nil withRowAnimation:UITableViewRowAnimationBottom]; [self.tableView endUpdates]; } @catch (NSException * e) { [self.tableView endUpdates]; dispatch_async(dispatch_get_main_queue(), ^{ [self.tableView reloadData]; }); } 

但是,如果indexPath是-1或超出边界,则catch处理程序无法处理,并且出现此错误:无效更新:第0节中的行数无效。在第更新(60)必须等于在更新之前在该部分中包含的行数(60),加上或减去从该部分插入或删除的行数(1插入,0删除)以及加或减的数量行移入或移出该部分(移入0,移出0)。

这不起作用

 @try { [self.tableView beginUpdates]; //try with nil to go to catch block [self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:-1 inSection:0]] withRowAnimation:UITableViewRowAnimationBottom]; [self.tableView endUpdates]; } @catch (NSException * e) { [self.tableView endUpdates]; dispatch_async(dispatch_get_main_queue(), ^{ [self.tableView reloadData]; }); } 

我这样做的原因是因为我试图debugging这个问题,为什么这个失败的原因,但在此期间,我想恢复这个问题,只刷新表而不是崩溃的应用程序。 如果失败,有什么办法可以撤销insertRowsAtIndexPaths吗? 提前致谢。