我有一个 UITableViewController,除了以下情况外,它工作得很好。
我按如下方式创建并呈现模态视图 Controller :
[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 在用户按下“完成”(rightBarButtonItem) 时调用继续,在用户按下“取消”(leftBarButtonItem) 时调用取消。
complete 进行网络异步调用并在请求完成后调用成功 block 。
在快乐路径中(即调用延续 block ),一切都很好。但是,当模态对话框在取消 block 中被关闭时,TableView 将完全消失。滚动有效,但只存在已经可见的单元格。滚动会导致一个空的 UI。 Delegate 和 Datasource 似乎设置正确,但它们似乎根本没有被调用。
我尝试了多种方法,包括改用委托(delegate)、在主线程中显式调用 dismiss 等。我现在不知道该尝试什么。
非常感谢任何有关我遗漏的线索,甚至是关于下一步尝试的指示。
我见过
- > UITableView delegates not getting called after NSURL delegates
- > UITableView Not refreshing after Modal View Controller dismisses
这两种情况似乎都是数据与 View 不同步的情况, 但是这两种情况都不适用,因为如果我选择快乐的路径(表中的数据确实发生了变化)并且在取消路径中,我根本不触及数据,那么一切都会奏效。
[更新]:此外,我的行操作不再有效。在快乐之路之前和之中,一切都很好。取消后,不再有编辑操作:-(
[更新]:添加了缺失的 beginUpdates
、endUpdates
调用,用于识别问题。
最佳答案
@Alex 是正确的。当您从它们之上关闭模态视图时,tableView 不会中断。
但是,当您beginUpdates
并忘记 endUpdates
时,它们的行为确实很奇怪。事实证明,在取消时,调用了 dismissViewController
,但没有调用 endUpdates。
确保您的 beginUpdates
和 endUpdates
匹配,否则 tableView 的行为会很奇怪。
关于iOS UITableView 在模式关闭后不再调用委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35318433/