I have pushed a view onto the navigation controller and when I press the back button it goes to the previous view automatically. I want to do a few things when back button is pressed before popping the view off the stack. Which is the back button callback function?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- Disable Browser onUnload on certain links?
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- How to create a CFuncType in Python
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
If you're using a Storyboard and you're coming from a push segue, you could also just override
shouldPerformSegueWithIdentifier:sender:
.I end up with this solutions. As we tap back button viewDidDisappear method called. we can check by calling isMovingFromParentViewController selector which return true. we can pass data back (Using Delegate).hope this help someone.
it's probably better to override the backbutton so you can handle the event before the view is popped for things such as user confirmation.
in viewDidLoad create a UIBarButtonItem and set self.navigationItem.leftBarButtonItem to it passing in a sel
Then you can do things like raise an UIAlertView to confirm the action, then pop the view controller, etc.
Or instead of creating a new backbutton, you can conform to the UINavigationController delegate methods to do actions when the back button is pressed.
If you can't use "viewWillDisappear" or similar method, try to subclass UINavigationController. This is the header class:
Implementation class:
In the other hand, you need to link this viewController to your custom NavigationController, so, in your viewDidLoad method for your regular viewController do this:
Here's another way I implemented (didn't test it with an unwind segue but it probably wouldn't differentiate, as others have stated in regards to other solutions on this page) to have the parent view controller perform actions before the child VC it pushed gets popped off the view stack (I used this a couple levels down from the original UINavigationController). This could also be used to perform actions before the childVC gets pushed, too. This has the added advantage of working with the iOS system back button, instead of having to create a custom UIBarButtonItem or UIButton.
Have your parent VC adopt the
UINavigationControllerDelegate
protocol and register for delegate messages:Implement this
UINavigationControllerDelegate
instance method inMyParentViewController
:If you specify a specific callback function in the above
UINavigationControllerDelegate
instance method}