简体   繁体   English

为什么有时弹出到根视图控制器会导致调用viewDidLoad?

[英]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. 我有一个基于导航的应用程序,并且在子视图中有一个按钮,点击该按钮会调用popToRootViewController方法。

-(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. 这应该导致调用rootViewController的viewWillAppear方法,并且在大多数情况下都在发生。 However, occasionally viewDidLoad of rootViewController is called. 但是,有时会调用rootViewController的viewDidLoad。 I am not able to find the reason behind it. 我找不到背后的原因。 Does any one has any idea why viewDidLoad is called sometimes? 有谁知道为什么有时会调用viewDidLoad吗?

viewDidLoad is called once when view controller's view is loaded first time. 首次加载视图控制器的视图时,将调用一次viewDidLoad

viewWillAppear will be called after viewDidLoad method when view controller's view is loaded first time. 首次加载视图控制器的视图时,将在viewDidLoad方法之后调用viewWillAppear

Now when ever u push or pop controller in navigationController , the visible controller's viewWillApper method will be called surely. 现在,当您在navigationController中推送或弹出控制器时 ,将肯定调用可见控制器的viewWillApper方法。

viewDidLoad , as the name implies, is called just after a view controller has loaded its view. 顾名思义, viewDidLoad是在视图控制器加载其视图之后立即调用的。 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). 如果视图控制器不再是最前端的控制器,则它可以释放其视图以节省内存(并且它曾经调用了iOS 6中已弃用的viewWillUnloadviewDidUnload )。 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 . 如果发生这种情况,当它再次出现(或每当有人调用thecontroller.view )时,它将重新创建视图(如果不是基于Nib的,它将调用loadView ),然后调用viewDidLoad

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

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