Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableView在catch块内重新加载数据_Ios_Objective C_Uitableview_Reloaddata - Fatal编程技术网

Ios UITableView在catch块内重新加载数据

Ios UITableView在catch块内重新加载数据,ios,objective-c,uitableview,reloaddata,Ios,Objective C,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];

我试图在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];
     });
}
有没有关于如何在更新失败时重新加载tableview的建议?谢谢

更新

所以我可以处理insertRowsAtIndexPaths:nil 这很有效

@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];
     });
}

我这样做的原因是因为我正在尝试调试这个问题,为什么这个问题一开始就失败了,但与此同时,我想从这个问题中恢复过来,只是刷新表,而不是使应用程序崩溃。如果失败了,有没有办法撤消insertRowsAtIndexPaths?提前谢谢。

你在我之前设置了断点n查看
@catch
是否触发?是的,它确实触发了tableview,然后必须刷新tableview。您的数据源是否正确更新?如果存在实际问题,则它不在您发布的代码中。请整合您的代码,以确保永远不会发生异常(这是可能的).Btw:
begin-/endUpdates
在本例中是语法糖。它根本没有任何效果。动画有一个问题,我仍在尝试调试:同时,我希望应用程序不要崩溃并加载数据,即使没有动画。谢谢。