In UINavigationController
, is there a way to button if the current viewcontroller is being dismissed as a result of the user pressing the back button or if the view controller is being dismissed programmatically with popViewControllerAnimated
?
Note: I am specifically trying to differentiate between the 2 events. This is not a duplicate of this question as I am trying to figure out which event was called, not when the view controller is being dismissed
To Clarify: I am trying to figure out whether the view is disappearing because
a) the back button was pressed or
b) popViewControllerAnimated was called
On viewWillDisappear method you can check values for isMovingFromParentViewController:
self.isMovingFromParentViewController()
which will return Bool, a Boolean value that indicates that the view controller is in the process of being removed from its parent.
Updated:
As replied, I think you will need to implement custom back button with its own method which can keep track of it.
self.navigationItem.leftBarButtonItem = nil;
self.navigationItem.hidesBackButton = true;
let backButton = UIBarButtonItem(title: "< Back", style: UIBarButtonItemStyle.Plain, target: self, action: nil)
backButton.setTitleTextAttributes([NSFontAttributeName: UIFont(name: "Chalkduster", size: 20)!], forState: UIControlState.Normal)
navigationItem.backBarButtonItem = backButton
backButton.addTarget(self, action: "backButtonMethod",forControlEvents:UIControlEvents.TouchUpInside)
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.