简体   繁体   中英

Login Screen using Storyboard

I am new to iOS 5 and trying to write my apps as pure iOS 5 app using the new storyboard feature.

I have a start screen (Login Screen) so I do not want to use navigationcontroller because i don't need any user to go back for a log-in screen after log-in successfully moreover, i don't need navigationbar because it's affect on the Home Screen Design.

So, I need to do a manual segue to the login screen, after checking the username and password for login:

If(Login Successful)
     Navigate to the Home View Controller
else
     Display Error Message.

Now is this even possible, or do I need 2 story boards for that ?

If(Login Successful){
      UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];

      HomeViewController* viewController = [storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];

      [self presentViewController:viewController animated:YES completion:nil];
}

Possible Duplicate of Question

Since using Navigation controller after embedding navigation controller in scene

If(Login Successful){
      UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
      HomeViewController* viewController = [storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
    [self.navigationController pushViewController:HomeViewController animated:YES];
}

You can achieve this with a manual segue. In the storyboard control-drag from the login screen view controller to the home view controller (make sure you are zoomed out in the storyboard, so that you are actually selecting the viewcontrollers and not the subviews in them), and select "modal" as the type of segue. Then select the segue itself and in the Attributes inspector give it an identifier, such as "loginSuccessful". Then in you can write:

If(Login Successful)
    [self performSegueWithIdentifier:@"loginSuccessful" sender:self];

This will present the view controller pointed by the segue in the storyboard. If you need to do extra setup of the home screen before showing it, you can do it in the prepareForSegue method like follows:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if(segue.identifier isEqualToString:@"loginSuccessful"){
        HomeViewController* target =(HomeViewController *) segue.destinationViewController;
        Target Setup;
    }
}

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