Perform segue after Login successful in Storyboards

后端 未结 3 1634
梦如初夏
梦如初夏 2020-12-03 20:51

I have 2 UITextFields, one of them for Login and the another for the Password.

Only if the Login is \"succesful\", I want to perform the Segue

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 21:07

    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) 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
                    }
                }
        }
    

提交回复
热议问题