[英]How do I perform an operation when the back button is pressed
I have two navigation Controllers for my views. 我的视图有两个导航控制器。 I need to perform some operations when the user presses the back button to go to the previous view. 当用户按下“后退”按钮转到上一个视图时,我需要执行一些操作。 Normally I would do this using the prepareForSague() function and using the sague Identifier. 通常,我将使用prepareForSague()函数并使用sague标识符来执行此操作。
What's the identifier (or how do I get it) of the back button that comes with navigation controller so i can use it in my prepareForSague function. 导航控制器随附的后退按钮的标识符是什么(或如何获取),因此我可以在我的prepareForSague函数中使用它。 Or is it done in other ways? 还是以其他方式完成?
Please follow the steps: 请按照以下步骤操作:
popToViewController
: method. 将目标选择器添加到该按钮,然后使用popToViewController
:方法。 Or 要么
Just place your code inside viewWillDissapear 只需将您的代码放在viewWillDissapear中
override func viewWillDisappear(animated: Bool)
That is, don't try to change the behavior of the back button, just write whatever code you need to be executed inside viewWillDissapear
也就是说,不要尝试更改后退按钮的行为,只需在viewWillDissapear
内编写需要执行的任何代码即可
you have to use "viewWillDissapear" method for this, if you wanna use default back button. 如果要使用默认的后退按钮,则必须使用“ viewWillDissapear”方法。
But you may have to be careful here coz you only need this to work when really going back by back button, so every other actin - which calls "viewWillDissapear" method, you may need to make a flag to know its not the back action. 但是您可能需要注意,因为只有在真正通过后退按钮返回时才需要使用此功能,因此每隔一个肌动蛋白-调用“ viewWillDissapear”方法,您可能需要标记以知道其不是后退动作。
您的类可以实现UINavigationControllerDelegate
协议并实现此方法:
- (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.