简体   繁体   中英

How to set root view controller of window to a UINavingationController when current root view controller of window is UITabBarController?

I have a UITabBarController which contains four navigation controllers. When user taps a button , I want to set the root viewController of window to a new navigation controller. How do I do that in Objective-C?

Using a modal view controller will look better than simply replacing the root view controller, and should produce the same effect as you are looking for. Basically, you create an instance of your view controller, add it to a new navigation controller, and then present the navigation controller modally:

- (void)buttonPressed
{
    MyViewController *vc = [[MyViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    [self presentViewController:nav animated:YES completion:nil];
}

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