简体   繁体   中英

iOS: modal transition to a black screen?

I'm writing an iPad app that has two main view controllers, the LoginController and ViewController. I need to be able to transition from the view controller to the login window again when a timeout happens. I am doing so like this:

LoginController *loginView = [[LoginController alloc] init];
[loginView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:loginView animated:YES completion:nil];

And the view does seem to transition properly, however, the contents of the view aren't being drawn. All I see is a black screen. What could be wrong?

I'm guessing you're using storyboards? If so, you just need to change this line:

LoginController *loginView = [[LoginController alloc] init];

First go to Interface Builder, and locate the Identity Inspector on the right bar. Assign and ID in the "Storyboard ID" box. Then in your code, you reference the view controller like this.

LoginController *loginView = [self.storyboard instantiateViewControllerWithIdentifier:@"theIDfromInterfaceBuilder"];

Your LoginController view is empty (doesn't have anything on screen) because you are alloc/init it. If you have a xib for that controller use

- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle

If you are using storyboards use

[self.storyboard instantiateViewControllerWithIdentifier:@"yourVCIdentifier"];

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