Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIViewController: detecting drill-down and drill-up

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.

like image 744
Norman Avatar asked Jul 02 '09 12:07

Norman


2 Answers

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.

like image 194
Matt Bridges Avatar answered Sep 29 '22 10:09

Matt Bridges


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.

like image 33
Kendall Helmstetter Gelner Avatar answered Sep 29 '22 10:09

Kendall Helmstetter Gelner