Paul
Paul

Reputation: 385

Immediately loading new view in IOS

Currently having a slight issue.

Basically my appdelegate is loading my mainViewController:

self.viewController = [[MainViewController alloc] initWithNibName:@"mainViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;

Now when the mainViewController loads, I want to check whether or not the user has logged in already:

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    NSInteger myInt = [prefs integerForKey:@"user"];
    if(!myInt)
    {
        self.loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
        self.loginViewController.delegate = self;
        self.loginViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
        [self presentModalViewController:self.loginViewController animated:YES];
    }
}

It successfully checks whether or not the user is logged in, and goes into the if statement if they are not logged in. However, after running it, the eventual view that loads is the mainViewController, not the loginViewController.

If I have a separate button to send me to the login page with this code, it works fine. Of course, that is not what I need, I need users to have to log in =p

Upvotes: 2

Views: 148

Answers (1)

jrtc27
jrtc27

Reputation: 8536

Put it into -viewDidAppear:.

Upvotes: 3

Related Questions