Perform segue after Login successful in Storyboards

感情迁移 提交于 2019-11-27 15:24:35

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.

Like so:

Nuno Vinhas

You are using the wrong logical operator.

User &&instead of & inside your if statement.

For better understand of the difference between the two I recommend you to read this other stack overflow answer.

Swift 4 You can still link UIButton to the View Controller and create a Segue. If your login is successful then invoke self.performSegue within your closure. Something like this...

@IBAction func loginButtonPressed(_ sender: AnyObject) {
        authenticateUser(email: email.text!, password: password.text!)
}

func authenticateUser(email: String, password: String){
        # Building your loginUrl goes here

        Alamofire.request(loginUrl!,
                          method: .post,
                          parameters: nil,
                          encoding: JSONEncoding.default,
                          headers: headers)
            .validate()
            .responseJSON { (response:DataResponse<Any>) in
                switch(response.result) {
                case .success(_):

                    let apiResponse : JSON = JSON(response.result.value!)

                    print("Now Performing Segue on IBAction Pressed")
                    self.performSegue(withIdentifier: "goToDashboard", sender: self)
                   break

                case .failure(_):
                    print(response.result.error)
                    break
                }
            }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!