简体   繁体   English

取消模态后,iOS UITableView不再调用委托

[英]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. [更新]:添加了缺少的beginUpdatesendUpdates调用,以识别问题。

@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. 确保您的beginUpdatesendUpdates匹配,否则tableView的行为会很奇怪。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS Obj-C - 当模态视图被解除时,UITableView数据消失 - iOS Obj-C - UITableView data disappears when modal view dismissed 父视图 controller 中是否有在模态视图被关闭后被调用的委托? - Is there a delegate in the parent view controller that gets called after a modal view gets dismissed? 收到内存警告并关闭“模式”视图后,UITableView似乎被部分裁剪(变黑) - UITableView appears partially clipped (blanked out) after receiving memory warning and “modal” view dismissed 首次导入后,iOS 10中的UITableview不再刷新 - UITableview No Longer Refreshing in iOS 10 after initial import 编辑器视图控制器关闭后,UITableView不更新 - UITableView not updating after editor view controller dismissed ios-如果关闭模态,如何在ViewController中调用方法 - IOS How to call a method in a ViewController if modal is dismissed iOS-模态UIView在内存警告后失去委托 - IOS - Modal UIView is loosing delegate after memory warning iPad模态控制器在旋转后被解雇 - iPad modal controller is dismissed after rotation Xamarin iOS UITableView在初始设置上调用所有单元的委托方法,而不仅仅是可见单元 - Xamarin iOS UITableView Calls Delegate Methods For ALL Cells on Initial Setup, Not Just Visible Ones NSFetchedResultsController(和UITableView)委托方法调用增长和增长 - NSFetchedResultsController (and UITableView) delegate methods calls growing and growing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM