Question

I am writing an iOS app that has a 3-4 level of drill down. In the 2nd, 3rd... and so on views, I want to add a home button on the nab bar, which once pressed takes you back to the root view controller, i.e. the first screen.

I have added a button using storyboard and simply want to implement the - (void) homeButtonpressed:(id)sender function so that my first view is displayed.

Also, if this is some kind of a built in functionality for this (like there is for back button), then that would be great, as I will need to write this piece of code in all my child views.

Can somebody help me with this?

Thanks!

Was it helpful?

Solution

You can pop to rootview by using the following code

[self.navigationController popToViewController: [self.navigationController.viewControllers objectAtIndex: 0] animated: YES];

or

[self.navigationController popToRootViewControllerAnimated:YES];

OTHER TIPS

Make an array of your view controllers Pops all the view controllers on the stack except the root view controller and updates the display.

- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated

[self.navController popToRootViewControllerAnimated:(BOOL)animated];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top