PresentModalViewController in an iOS 5 software storyboard

This is the first time I'm using storyboards in my iOS app. I have 2 views in my storyboard (A & B). Let's say A is my initial view controller in my storyboard. When my application is running, I see the view controller A. So far, everything is working as expected. Now in my view controller A, I check to see if the user is logged in or not. If the user is not logged in, I want to present the view controller B. How can I show B modally using PresentModalViewController programmatically?

Here are my settings

enter image description here

Here is my code

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    if (!isUserLoggedIn) {
        NSLog(@"USER NOT LOGGED IN....");
        UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        LoginViewController *vc = (LoginViewController*)[mainStoryboard instantiateViewControllerWithIdentifier:@"B"];
        [self presentModalViewController:vc animated:YES];
    }
}
+5
source share
1 answer

, , . , B ?

,

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

, .

Update:

viewDidLoad:

- (void)viewDidLoad {

    [super viewDidLoad];

    if (!isUserLoggedIn) {

        NSLog(@"User is not logged in.");

        LoginViewController *vc = (LoginViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"B"];
        [self presentModalViewController:vc animated:YES];

    }

}

, , - . "View Controller", " " ​​.

. Xcode , .

+10

All Articles