UIViewController: Define Sweep and U-Turn

Is there a way for the UIViewController (inside the navigation stack) to determine if this is due to a sweep or sweep?

In viewWillAppear, unfortunately, the UTIavigationController topViewController and visibleViewController are already installed on the new ViewController.

+7
iphone uiviewcontroller uinavigationcontroller
source share
4 answers

You can subclass UINavigationController and add the didPushViewController property. You can then override pushViewController and popViewController to correctly set the property to true or false respectively.

+5
source share

Another way is to hide any view controllers that you are drilling as local class variables - then in viewWillAppear you know that you were hit due to granularity if any of the local class variables are still set. You even know which controller the user is returning from, so you can do other logic (for example, choosing from the changed values ​​from the view controllers that you deployed).

Remember to release and delete links in viewWillAppear so that the reset system recognizes things again.

I like this mechanism more than drilling dispatchers who know about the main view as a delegate in order to push out the changes, as they often work on some separate small pieces of data and do not need to know about the whole main controller. This facilitates their reuse, as they can be called by different classes.

+2
source share

You just need to know what will happen to the previous and subsequent controllers? Or do you need to specifically know if the view controller has been displayed or pressed? You can implement the following method, which is defined by UINavigationControllerDelegate :

 - ( void )navigationController:( UINavigationController * )navigationController willShowViewController:( UIViewController * )viewController animated:( BOOL )animated { UIViewController * currentController = navigationController.visibleViewController; UIViewController * nextController = viewController; // Do whatever here. } 

If, however, you need to know if a particular view controller has been pushed out or pushed, then Matt Bridges' suggestion is the way to go.

+1
source share

Could you take a look at the viewControllers property in the navigation controller?

0
source share

All Articles