简体   繁体   中英

xcode changing view controllers issues

I have been developing an iPhone app and have come across a few issues. I do not have a storyboard in my app and have nothing in my xibs. I have initialised and set everything up through code. When I go to the GameViewController from my main viewcontroller everything is fine, however when I come back through my back button I get this issue:

Presenting view controllers on detached view controllers is discouraged .

When I re-arrive to the main view controller, there are little changes such as the view changing before its supposed to. Here is the code for the button on my

GameViewController *game = [[GameViewController alloc] initWithNibName:nil bundle:Nil];
    [self dismissViewControllerAnimated:YES completion:NULL];
    [self presentViewController:game animated:YES completion:NULL];

Here is the code for the back button:

ViewController *home = [[ViewController alloc] initWithNibName:nil bundle:nil];

[self dismissViewControllerAnimated:YES completion:NULL];
[self presentViewController:home animated:NO completion:NULL];

If anyone can help me to see what I am doing wrong that would be great.

You can not present home view controller from self because it is already dismissed. You should change

[self dismissViewControllerAnimated:YES completion:NULL];
[self presentViewController:home animated:NO completion:NULL];

to

UIViewController *parentViewController = self.presentingViewController;
[self dismissViewControllerAnimated:YES completion:^
 {
     [parentViewController presentViewController:home animated:NO 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