One UIButton - two scenes in only one segment, conditional code required

I created several scenes in the storyboard file in my Xcode project, and the first script loaded is the user's login to the screen. When a user logs on to UIButton, "Login" displays the user on the welcome screen. I customize this in the storyboard using a modal transition. I want a user named "admin" to receive an admin welcome screen. I am sure that only one segue is possible associated with one object, that is, UIButton in the storyboard, so I can’t say how I can log in to send the administrator to the administrator’s welcome screen and all other users the user’s welcome screen. I really don't want to create two separate login buttons, so this is not an option.

I came across some stackoverflow posts with similar questions, but all the answers seemed a bit confusing. Keep in mind that I'm new to Xcode, so if you paste the code in your answer, specify which file the code should go to (which will help me get a LOT). I will post an image of what the storyboard will show me to demonstrate a visual diagram of what I'm talking about.

enter image description here

+5
source share
2 answers

If I understand your question correctly, here are the steps you need to take to get it working:

  • WelcomeViewController, /, UIViewController WelcomeScreen Modal ( UIViewController , UIViewController , , ). segue "UserSegue"

  • 1, + Admin. segue "AdminSegue"

  • WelcomeViewController,

  • -(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];
        }
    }
    
  • 4.

+6

- ( ).

segues . , ( ), segues , - , , .

segue , ( ) IB . segue (, "mySegue" ).

, . ( , ), , , [self performSegueWithIdentifier:@"mySegue"] .

, .

+1

All Articles