user1534235 user1534235 - 8 months ago 46
iOS Question

Home button in drill down app

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!

Answer Source

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];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download