简体   繁体   中英

How to navigate from subview to other view controller?

Assume that I am having one view controller called MainPage(This is rootViewController). In that view controller , I am adding one sub view.

See Below :

FirstPage1=[[FirstPage alloc] initWithNibName:@"FirstPage" bundle:[NSBundle mainBundle]];
[self.view addSubview:FirstPage1.view];

In that subview , I need to navigate to next page.

so that i have used presentViewController like below code but its doen't worked well.

See Below Code:

[self.view.window.rootViewController presentViewController:AnotherViewController animated:YES completion:nil];

It works well on first time but if I called for next time , I got below error.

Error : whose view is not in the window hierarchy!

Having separate view controllers being linked together is a good use for UINavigationController . Just make a UINavigationController and add its view to self.view on your example. Then, do [navController pushViewController: animated:] for each view as needed. Or pop the last view controller, then push the new one if you don't want old pages to be accessible. From how your project seems to be set up, that's the easiest way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM