简体   繁体   中英

Why popping to root view controller results in calling viewDidLoad sometimes?

I have a navigation based application and in the child view I have a button, tapping on which results in calling the popToRootViewController method.

-(IBAction)popToRootViewController
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

This should result in calling the viewWillAppear method of the rootViewController and it is happening in most of the cases. However, occasionally viewDidLoad of rootViewController is called. I am not able to find the reason behind it. Does any one has any idea why viewDidLoad is called sometimes?

viewDidLoad is called once when view controller's view is loaded first time.

viewWillAppear will be called after viewDidLoad method when view controller's view is loaded first time.

Now when ever u push or pop controller in navigationController , the visible controller's viewWillApper method will be called surely.

viewDidLoad , as the name implies, is called just after a view controller has loaded its view. If a view controller is no longer the frontmost controller, it may release its view to save memory (and it used to call viewWillUnload and viewDidUnload which are now deprecated in iOS 6). If this happens, when it comes to front again (or whenever something calls thecontroller.view ), it will recreate the view (if is not Nib-based, it will call loadView ), and then call viewDidLoad .

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