简体   繁体   English

取消模式视图后的可见视图控制器

[英]Visible View Controller after dismissing modal view

I would like to know why tha't happening: I have 2 view controllers embeded in navigation controller. 我想知道为什么不会发生:我在导航控制器中嵌入了2个视图控制器。 All have superclass where I have something like that: 所有人都有超类,而我有这样的东西:

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSLog(@"Visible VC: %@",self.navigationController.visibleViewController.class);
}

So far everything works like a charm. 到目前为止,一切都像魅力。 Then I added third navigation controller which is the modal view controller. 然后,我添加了第三个导航控制器,即模态视图控制器。 It also has super class like the others. 它也像其他人一样具有超级阶级。 Now I see strange thing. 现在我看到了奇怪的事情。 After click button to present modal View controller I see log: "Visible: (null)", but it's ok because third VC is not in navigation controller. 单击按钮以显示模式视图控制器后,我看到日志:“可见:(空)”,但是可以,因为第三个VC不在导航控制器中。 When i click dismiss button to hide modal View controller I see 2 logs: "Visible: (null) Visible: ViewController3". 当我单击关闭按钮以隐藏模态视图控制器时,我看到2条日志:“可见:(空)可见:ViewController3”。 My question is: Why visible view controller is not kind of class ViewController2 ? 我的问题是:为什么可见的视图控制器不是ViewController2类? It should be, because third one was dismissed. 应该的,因为第三人被解雇了。 How can i resolve it ? 我该如何解决? I need to have visible view controller kind of class View Controller 2. 我需要类View Controller 2的可见View Controller类。

I'm guessing that viewController2 is not the visible one yet when that is called. 我猜想当viewController2被调用时它还不是可见的。

Try accessing it in 尝试访问它

viewDidAppear

instead of viewWillAppear. 而不是viewWillAppear。

Or, you can try to access the 或者,您可以尝试访问

self.navigationController.topViewController

property instead, that should return viewController2. 属性,应返回viewController2。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM