iOS UITableView 在模态关闭后不再调用委托

iOS UITableView no longer calls delegate after modal dismissed

我有一个 UITableViewController,除了以下情况外,它工作得很好。

我创建并展示了一个模态视图控制器,如下所示:

[self.tableView beginUpdates];
NSMutableDictionary *request_params = [NSMutableDictionary new];
InputViewController *inputController = [[InputViewController alloc] initWithParams:request_params 
    continuation:^(UIViewController * thisInputController) {  
      [self complete:request_params success:^() {  
        [self.navigationController dismissViewControllerAnimated:YES completion:nil];  
        [self.tableView endUpdates]; # Added in 
      } failure:nil];  
    } cancel:^{  
      [self.navigationController dismissViewControllerAnimated:YES completion:nil];  
    }];  
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:inputController];  
[self.navigationController presentViewController:nav animated:YES completion:nil]; 

InputViewController 在用户按下 'Done'(rightBarButtonItem)时调用继续,并在用户按下 'Cancel'(leftBarButtonItem)时取消。

complete 进行网络异步调用并在请求完成后调用成功块。

在快乐的道路上(即调用延续块),一切都很好。但是,当模态对话框在取消块中被关闭时,TableView 将完全消失。滚动有效,但只存在已经可见的单元格。滚动结果为空 UI。 Delegate 和 Datasource 似乎设置正确,但它们似乎根本没有被调用。

Before Scroll After scroll

我尝试了多种方法,包括改用委托、在主线程中显式调用 dismiss 等。我现在不知道该尝试什么。

非常感谢任何关于我遗漏的线索,甚至是关于下一步尝试的指示。

我看过

这两种情况似乎都是数据与视图不同步的情况, 但是这两种情况都不适用,因为如果我选择快乐的路径(数据确实在 table 中发生更改)并且在取消路径中,我根本不接触数据。

[更新]:此外,我的行操作不再有效。在快乐之路之前和之中,一切都很好。取消后,不再有编辑操作:-(

[更新]:添加了缺失的 beginUpdatesendUpdates 调用,确定了问题。

@Alex 是正确的。当您从它们之上关闭模态视图时,tableView 不会中断。

但是,当您 beginUpdates 忘记 endUpdates 时,它们的行为确实很奇怪。事实证明,在取消时,dismissViewController 被调用,但 endUpdates 没有被调用。

确保您的 beginUpdatesendUpdates 匹配,否则 tableView 的行为会很奇怪。