Search code examples
iosuinavigationcontrollerpoptoviewcontroller

How many layers deep in UINavigation?


How do you see how many layers you are removed from rootViewController in stack with UINavigation?


Solution

  • This depends on how your view hierarchy is setup. If you root view controller is a navigation controller and all you have done is pushed view controllers on to the navigation controller then simply look the 'viewControllers` property of the navigation controller. Its count tells you how many view controllers have been pushed.

    NSUInteger count = [self.navigationController.viewControllers count];
    

    It gets a bit more complicated if you have presented any modal controllers onto the stack.