문제

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!

도움이 되었습니까?

해결책

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

다른 팁

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];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top