UINavigationController: willShowViewController Question

I am confused by this delegate post. I have a navigation controller in a PopupViewController. When I click on the new viewController, I don’t know what the viewController is, that it is currently displayed before the new one is clicked ...

I tried getting navigationController.topViewController and navigationController.visibleViewContrller, but both of them are always equal to the viewController that will push it ... It looks like I get a message after the point has been clicked

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{ UIViewController *currentViewController = navigationController.topViewController; if(currentViewController == viewController){ /// THIS IF STATEMENT IS ALWAYS TRUE } } 

Has anyone stumbled upon something like this?

+4
source share
1 answer

Was there any kind of digging into the UINavigationController Class Reference , and it looks like you can use the viewControllers property of the UINavigationController class.

The root view controller (at the bottom of the navigation stack) is at index 0 with the back view controller (the one just covered) with index n-2 and the topViewController property is at index n-1 , where n is the number of view controllers in the array.

As with iOS 7 and Xcode 5.x, you can send the firstObject message to the array returned by the viewControllers property to get the root view manager. Similarly, the topViewController property can be obtained by sending the lastObject message to the array returned by the viewControllers property.

+5
source

All Articles