简体   繁体   中英

Presented UIViewController disappears after segue animation

In my app, I want to present another view controller from my initial view controller.

I tried that with instantiating it from the storyboard, because I want the segue to be automatically executed after a certain time.

UIViewController* secondViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ViewController"];
[self presentViewController:officialFirstViewController animated:YES completion:nil];  

After secondViewController is presented, just about when the segue animation has finished, the view controller disappears and i see a black screen (the window?).

I tested around a bit and I learned that if I do something in the SecondViewController.m, like eg

self.view.backgroundColor = UIColor.orangeColor;

in the viewDidLoad, the secondViewController doesn't disappear anymore.
Is that, because now a strong reference is held to secondViewController?

Also, if I change the modalPresentationStyle of the secondViewController to UIModalPrestationOverFullScreen before presenting it, it doesn't disappear either:

UIViewController* officialFirstViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ViewController"];
officialFirstViewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self presentViewController:officialFirstViewController animated:YES completion:nil];

I believe, these two solutions have has something to do with a strong reference to the secondViewController, but I don't understand, why and I would rather have a solution that feels clean.

I would be very happy if anybody could help me with this problem.

try below code,

 UIViewController *td=[self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"];

 [self.navigationController pushViewController:td animated:YES];

Okay, I am really ashamed.

The view controller was there all the time. It just had the "default" background color, which let him look like the key window.

Changing the background color just changed the background color and it had nothing to do with references.

Perhaps this can help somebody who went through the same problem. :)

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