1

I am a new iOS developer developing my first iPhone app on commission.

I am a little unsure as to the correct way of navigating between a hierarchy of view controllers on two levels. I am navigating between 5 view controllers at the first level using a toolbar with a UINavigationController.

I need one of my toolbar buttons at this top level to navigate to any one (which one is determined by previous user activities at this level) of 6 related view controllers which should be at the same level (level 2). Within these view controllers the toolbar should then provide buttons for transferring control to each of the other view controllers at this level, but without pushing them onto the navigation controller stack underneath the previously viewed view controller at this level. ie I want the nav controller back button to go straight back to the top level however many of the second level view controllers have been viewed. How do I do this?

I hope my question is understandable. No doubt the answer is simple. Any advice gratefully received.

Adam Strait
  • 365
  • 1
  • 14

2 Answers2

1

I think you can try UITabBarController for viewcontrollers in same level.

Edit : For Using UITabBarController inside Navigationcontroller, Check these SO POST 1

SO POST 2

Community
  • 1
  • 1
Adarsh V C
  • 2,314
  • 1
  • 20
  • 37
  • I have seen posts relating to UITabBarController which suggest that it would need to be set up in the appDelegate as the root view controller with the nav controller as a subview. I am assuming that this works at the top level. Is it possible to just add a tab bar at level 2. If so what do I add it to? – Adam Strait Aug 21 '13 at 10:08
  • Another option is to use UITableView as menu to navigate towards different viewcontrollers. – Adarsh V C Aug 21 '13 at 10:11
  • Design constraints preclude the use of a table view for this app. – Adam Strait Aug 21 '13 at 10:13
  • Edited my answer to include some SO discussions you can refer. – Adarsh V C Aug 21 '13 at 10:22
  • 1
    Thanks for the edit with the SO discussion links. Somewhere in those discussions is the correct solution. – Adam Strait Aug 21 '13 at 11:06
  • 1
    After reading these discussions I decided to access the second level modally, with a tab bar for moving between the view controllers at this level. This way, I (hopefully) stick to Apple's design guidelines. – Adam Strait Aug 22 '13 at 09:10
  • 1
    What I actually did was to use view controller containment, with a new parent view controller, called modally, with transitions to the six children controlled by a segmented control in the parent. – Adam Strait Aug 26 '13 at 15:52
0

after entering to controllers from toolbar, call this function to delete navigation stack

- (void)removeNavigationStack{

    NSMutableArray *controllers = [self.navigationController.viewControllers mutableCopy];
    [controllers removeObjectsInRange:NSMakeRange(1, controllers.count-2)];
    self.navigationController.viewControllers = controllers;

}
pskow
  • 135
  • 1
  • 9