Swift: Navigate to new ViewController using button

后端 未结 1 1761
后悔当初
后悔当初 2020-12-03 03:34

I have a single view application which connects to parse and verifies user log in information and updates a UILabel saying \"Yay, You\'ve logged in sucessfully\" - Now I wan

相关标签:
1条回答
  • 2020-12-03 04:34

    First off as I explain in this answer, you need to drag the segue from the overall UIViewController to the next UIViewController, i.e. you shouldn't specifically connect the UIButton (or any IBOutlet for that matter) to the next UIViewController if the transition's conditional:

    storyboard segue

    You'll also need to assign an identifier to the segue. To do so, you can select the segue arrow then type in an identifier within the right-hand panel:

    segue identifier

    Then to perform the actual segue, use the performSegueWithIdentifier function within your conditional, like so:

    if user != nil {
        self.messageLabel.text = "You have logged in";
        self.performSegueWithIdentifier("segueIdentifier", sender: self)
    } else {
        self.messageLabel.text = "You are not registered";
    }
    

    where "segueIdentifier" is the identifier you've assigned to your segue within the storyboard.

    0 讨论(0)
提交回复
热议问题