简体   繁体   中英

Show screen after login in iOS Objective C

I have a 2 viewControllers in my storyboards, I am making a login (all with objective C), when the credentials are OK I need to show another screen (and send data if is possible), but I found examples with segues and take the button to do it, I dont want to set the button to the segue because when I push it the another screen will be shown

I need to show the new screen only on the condition "if credentials are ok"

You can create a seque, give it some id and then call like this when you need to:

[self performSegueWithIdentifier:@"loginSeque" sender:self];

You can create login button action manually and try below code.

- (IBAction)LoginButtonAction:(id)sender {

    if ([self validated]) {    // check login validation on "validate" method. 

         UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
         HomeVC *home = [story instantiateViewControllerWithIdentifier:@"HomeVC"];

         UINavigationController *NavigationController = [[UINavigationController alloc] initWithRootViewController: home];    // for set HomeVC as a root view controller.

         [[UIApplication sharedApplication].keyWindow setRootViewController:NavigationController];
    }
}

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