I have created several scenes within a storyboard file in my Xcode project, and the first scene that is loaded is a user login in screen. When a user logs in the UIButton "Login" takes the user to the welcome screen. I setup that in storyboard using a modal segue. I want a user with the name "admin" to be taken a welcome admin screen. I'm pretty sure it's only possible to have one segue associated with one object, i.e. UIButton in storyboard, so I am stumped as to how I can accomplish the login to take the admin to the admin welcome screen, and take all other users to the user welcome screen. I really don't want to create two separate login buttons, so that's not an option.
I came across some stackoverflow posts with similar questions but all the answers seemed a little convoluted. Keep in mind I am new to Xcode, so if you paste code in your answer please specify which file the code should go in (that would help me out A LOT). I'll post a picture of what my storyboard looks like so far to help demonstrate a visual diagram of what I am talking about.
If I understood your question correctly, here are the steps you need to take to make it work:
From the WelcomeViewController
– where you have the username / password login button, control+drag from the UIViewController
to the WelcomeScreen
, and choose Modal
from the pop up menu (By drag from UIViewController I mean, select the UIViewController
in storyboard, there is a round shape icon on the bottom, from that to the destination view controller). Name the segue identifier as "UserSegue"
Repeat step 1, but instead control+drag it to Admin
screen. Name the segue identifier as "AdminSegue"
You need now to subclass WelcomeViewController
,
Implement -(IBAction)login:(id)sender
- (IBAction)login:(id)sender { // assuming you have hooked up the user name text field if ([self.usernameTextField.text isEqualToString:@"admin"]) { [self performSegueWithIdentifier:@"AdminSegue" sender:sender]; } else { [self performSegueWithIdentifier:@"UserSegue" sender:sender]; } }
In storyboard, hook up the login button to the method in step 4.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With