简体   繁体   English

在ios中点击后退按钮后调用什么方法

[英]What method is called after tap back button in ios

I have 2 View Controllers with Navigation Controller. 我有2个带导航控制器的视图控制器。 When I Use [self.navigationController popViewControllerAnimated:YES]; 当我使用[self.navigationController popViewControllerAnimated:YES]; in the second one - the first one opens but the methods in viewDidLoad don't called. 在第二个 - 第一个打开,但viewDidLoad中的方法不会被调用。 What are the methods called in the first one controller in this situation? 在这种情况下,第一个控制器中调用的方法是什么?

The navigation controller sends viewWillAppear: to a view controller before putting its view on the screen, and viewDidAppear: after. 导航控制器在将视图放在屏幕上之前将viewWillAppear:发送到视图控制器,以及viewDidAppear: after。

Inside viewWillAppear: and viewDidAppear: , the view controller can check self.isMovingToParentViewController . viewWillAppear:viewDidAppear: ,视图控制器可以检查self.isMovingToParentViewController If isMovingToParentViewController is YES , the view controller is being added to the navigation controller in the first place (presumably because it's the navigation controller's root view controller, or because it is being pushed). 如果isMovingToParentViewControllerYES ,则视图控制器首先被添加到导航控制器(可能是因为它是导航控制器的根视图控制器,或者因为它被推送)。 If isMovingToParentViewController is NO , the view controller is already in the navigation controller's stack, and another view controller is being popped to reveal it. 如果isMovingToParentViewControllerNO ,则视图控制器已经位于导航控制器的堆栈中,并且正在弹出另一个视图控制器以显示它。

Read “Handling View-Related Notifications” in the UIViewController class reference . 阅读UIViewController类引用中的“处理与视图相关的通知”

In that case viewWillAppear method will be called. 在这种情况下,将调用viewWillAppear方法。

-(void)viewWillAppear:(BOOL)animated
{

}

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

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