简体   繁体   中英

Presenting Main View Controller from a Child View Controller

I have a main view controller and am presenting a child view. For one of the settings inside the child, I need to call the main view controller again. It would just make things a lot easier.

The following causes a hierarchy problem:

#define appDelegate (MyAppDelegate *)[[UIApplication sharedApplication] delegate]

[self presentViewController:[appDelegate mainViewController] animated:YES completion:^{}];

Is there any way to call the mainViewController easily while not losing the state of the child view?

EDIT

Here is how I'm presenting the child view.

ChildViewController *childViewController = [[ChildViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:childViewController];
[childViewController release];
[self presentModalViewController:navigationController animated:NO];
[navigationController release];

You can't present a view controller that has already been presented or is in a navigation stack. What is the mainViewController? Did you instantiate it? Has it been added to the screen yet?

If yes to both, you either need to back into it (dismiss to it) or remove it from it's parent first and then present it.

在子视图中,您应该有权访问应用程序委托及其mainViewController属性,如下所示:

    MyApplicationDelegate *appDelegate = (MyApplicationDelegate *)[[UIApplication sharedApplication] delegate];

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