Domanda

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!

È stato utile?

Soluzione

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];

Altri suggerimenti

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];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top