简体   繁体   中英

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. 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. When i click dismiss button to hide modal View controller I see 2 logs: "Visible: (null) Visible: ViewController3". My question is: Why visible view controller is not kind of class 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.

I'm guessing that viewController2 is not the visible one yet when that is called.

Try accessing it in

viewDidAppear

instead of viewWillAppear.

Or, you can try to access the

self.navigationController.topViewController

property instead, that should return viewController2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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