简体   繁体   English

如何判断在UINavigationControllerStack中按下后退按钮的时间

[英]How to tell when back button is pressed in a UINavigationControllerStack

Is it possible to check when the back button is pressed in a UINavigationController stack? 是否可以检查何时在UINavigationController堆栈中按下后退按钮? I've tried adding a action and target to self.navigationItem.backBarButtonItem to no avail. 我已经尝试将一个动作和目标添加到self.navigationItem.backBarButtonItem无济于事。

Anyone have any solutions? 有人有任何解决方案?

You can try my way: 你可以尝试我的方式:

Write in your ViewController: 在ViewController中写入:

UIBarButtonItem *backBt = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"imageNameOfBackButton"] style:UIBarButtonItemStyleBordered target:self action:@selector(backBt_touch:)];
self.navigationItem.leftBarButtonItem = backBt;

And action method: 和行动方法:

- (void)backBt_touch:(id)sender {
  [self.navigationController popViewControllerAnimated:YES];
}

You have to take a photo of back button you want. 你必须拍一张你想要的后退按钮的照片。

Animation of hiding back button when viewController is popped is not the same animation of iOS! 弹出viewController时隐藏按钮的动画与iOS的动画不同!

P/s: P / S: 在此输入图像描述 I've get it from simulator. 我从模拟器中得到它。 Hope it useful! 希望它有用! :) :)

One way to get at this would be to override viewWillDisappear in the UIViewController that is visible when the back button is pressed: 实现此目的的一种方法是覆盖按下后退按钮时可见的UIViewController中的viewWillDisappear

- (void)viewWillDisappear:(BOOL)animated {
    if (self.isMovingFromParentViewController) {
        // handle back button press
    }
}

Obviously this doesn't directly intercept the press on the back button itself, but it gives you a chance to perform logic at that time. 显然这并没有直接拦截后退按钮本身的按键,但它让你有机会在那时执行逻辑。

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

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