[英]iOS UITableView no longer calls delegate after modal dismissed
I have a UITableViewController that works perfectly fine except in the following situation. 我有一个UITableViewController,除了在以下情况下,它工作正常。
I create and present a modal view controller as follows: 我创建并呈现一个模态视图控制器,如下所示:
[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 calls continuation when user presses 'Done' (rightBarButtonItem) and cancel when user presses 'Cancel' (leftBarButtonItem). 当用户按下“完成”(rightBarButtonItem)时,InputViewController调用继续;当用户按下“取消”(leftBarButtonItem)时,InputViewController取消。
complete makes a network async call and calls the success block upon completion of the request. complete发出网络异步调用,并在请求完成后调用成功块。
In the happy path (ie continuation block is called), all is good. 在幸福的道路上(也就是连续块被称为),一切都很好。 However, when the modal dialog is dismissed in the cancel block, the TableView gets completely hosed. 但是,当在取消块中取消模式对话框时,TableView将完全被清理掉。 The scrolling works, but only the cells that were already visible are present. 滚动有效,但仅存在已经可见的单元格。 Scrolling results in an empty UI. 滚动会导致一个空的UI。 Delegate and Datasource seem to be set correctly, but they don't appear to be getting called at all. Delegate和Datasource似乎设置正确,但是似乎根本没有被调用。
Before Scroll After scroll 滚动前滚动 后
I have tried multiple things include using delegates instead, explicitly calling dismiss in the main thread etc. I am now at a loss on what to try. 我已经尝试了多种方法,包括改为使用委托,在主线程中显式调用dismiss等。现在,我对尝试方法一无所知。
Would really appreciate any clues on what I'm missing or even pointers as to what to try next. 真的很感谢我所缺少的任何线索,甚至是下一步的指示。
I have seen 我见过
Both cases seem to be cases of data being out of sync with the view, but neither situation applies since things work if I take the happy path (where data does get changed in the table) and in the cancel path, I do not touch the data at all. 两种情况似乎都是数据与视图不同步的情况,但是这两种情况都不适用,因为如果我采用快乐路径(表中的数据确实发生了更改)而在取消路径中却不碰,数据。
[UPDATE]: Also, my row actions no longer work. [更新]:此外,我的行操作不再起作用。 Before & in the happy path everything is good. 在幸福的道路上和之前,一切都很好。 After a cancel though, no more edit actions :-( 取消后,不再有编辑操作:-(
[UPDATE]: Added the missing beginUpdates
, endUpdates
calls, that identifies the problem. [更新]:添加了缺少的beginUpdates
, endUpdates
调用,以识别问题。
@Alex was correct. @Alex是正确的。 tableView's do not break when you dismiss a modal view from on top of them. 当您从其顶部关闭模式视图时,tableView不会中断。
However, they do behave quite strangely when you beginUpdates
and forget to endUpdates
. 但是,当您开始beginUpdates
并忘记使用endUpdates
时,它们的行为确实很奇怪。 It turns out that when canceling, the dismissViewController
is getting called, but the endUpdates wasn't. 事实证明,取消时将调用dismissViewController
,但未调用endUpdates。
Make sure your beginUpdates
and endUpdates
match up or the tableView will behave quite strangely. 确保您的beginUpdates
和endUpdates
匹配,否则tableView的行为会很奇怪。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.