0

I currently have a tableview that has 3-5 rows. Currently designing a 5 page manual sort of. the idea is each row is supposed to link to their own individual view controller. In each of the 5 individual view controllers I have toolbars at the bottom of the controlleer which have buttons that will link it to the next page and the previous page. I was using storyboard and segues to do this in XCODE 4.3.2 . The problem I am experiencing is that say I click row 1. It takes me to page 1 and click next at the bottom toolbar, this will take me to page 2. Now I want to return to the original overview with all of the rows. I am supposed to do this through the back button in the nav toolbar, however it just takes me to page 1. Can someone please help me? Would be extremely grateful! :)

Masterminder
  • 1,127
  • 7
  • 21
  • 31

2 Answers2

1

A UINavigationController keeps a list (stack) of the UIViewControllers you have pushed onto it, and the automatic back button it displays takes you one step down in the stack. You're simply pushing the new view controller onto the stack, so when it goes back, it goes back to the last page, not the index. There are two ways around that: manipulate the stack directly (i.e. replace the old page with the new one, instead of pushing the new on top), or use a custom back button (probably using the -popToViewController:animated: selector). See the "Updating the Navigation Bar" section of the UINavigationViewController API docs.

Kevin
  • 53,822
  • 15
  • 101
  • 132
  • Can I still customize the back button if my navigation controller has the Top Bar "inferred" already? like at the moment I made the navigation bar show up on every controller so can I edit the back button from one of my "page controllers"? – Masterminder Jun 24 '12 at 16:40
  • Yes, each view controller has its own independent navigation bar setup. – Kevin Jun 24 '12 at 16:41
  • Okay thanks for the help Kevin. I am new to this iOS development so I guess I would have to make an outlet and then set it from there? - (NSArray *)popToRootViewControllerAnimated:(BOOL)animated or should this be implemented in another method? Like how would I implement it? – Masterminder Jun 24 '12 at 16:50
  • I don't use interface builder much, but I think you just need to drag a "Bar Button Item" onto the left side of the navigation bar, set the title, and connect the "selector" property to the method you write to pop to the right place. – Kevin Jun 24 '12 at 17:02
  • Do you know if I can modify the current back button that is there instead of making another button. I kind of want to keep the same shape etc – Masterminder Jun 24 '12 at 17:18
  • It appears to be difficult to do that without using undocumented APIs. You could change the "next" button so that it pops the current view controller before pushing the next. – Kevin Jun 24 '12 at 18:13
0

To return to the first view controller, use - (NSArray *)popToRootViewControllerAnimated:(BOOL)animated method of UINavigationController.

Zeus Alexander
  • 563
  • 2
  • 10
  • Can I still customize the back button if my navigation controller has the Top Bar "inferred" already? like at the moment I made the navigation bar show up on every controller so can I edit the back button from one of my "page controllers"? – Masterminder Jun 24 '12 at 16:40