问题
I have a simple test project with a UINavigationController as my rootViewController.
I push the first ViewController which has a + button as right bar button item, I subscribe to its taps to present a new ViewController (which is identical to the previous one).
The push segue works as I expect.
UIKit manages the back button for me and I think it is UINavigationController that makes the magic behind the scene.
Now, what I need to do is subscribe to the back button, but I can't find how to do this. I have tried with
navigationController.navigationBar.backItem?.backBarButtonItem?.rx.tapnavigationController.navigationItem.backBarButtonItem?.rx.tapbut they seem to be nil, so the optional chaining prevents subscription.
Thanks for your help, Luca-
回答1:
I think your best bet here is to use the operator on UINavigationController.
navigationController.rx.willShow will trigger whenever a view controller is about to be shown. You can do any last minute clean up when it fires.
来源:https://stackoverflow.com/questions/44609844/subscribe-to-uinavigationcontroller-back-button-with-rxswift-rxcocoa