Is there a way for a UIViewController (inside a navigation stack) to detect whether it is appearing because a drill-down or a drill-up was performed?
In viewWillAppear, the UINavigationController's topViewController and visibleViewController are already set to the new ViewController, unfortunately.
You could subclass UINavigationController, and add a property didPushViewController
. Then you can override pushViewController
and popViewController
to correctly set the property to true or false respectively.
Another way is to stash any view controllers you are drilling down to as class local variables - then in viewWillAppear, you know you were hit because of a drill-up if any of the class local variables are still set. You even know which controller the user returned from, so you can do different logic (like fetching changed values from the view controllers you drilled down to).
Don't forget to release and nil out the references in viewWillAppear so that the system is reset to recognize things properly again.
I like this mechanism more than having the drill-down controllers know about the master view as a delegate to push changes out, as often they are working on some separate small piece of data and shouldn't have to know about a whole master view controller. It makes them easier to reuse as well since they can be called up by many different classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With