waitUntilAllTasksAreFinished error Swift

前端 未结 4 1442
抹茶落季
抹茶落季 2021-01-31 16:23

I have this call in my loginViewController when Submit button is pressed:

let http = HTTPHelper()
    http.post(\"http://someUrl.com/Login/userEmail/\\(username.         


        
4条回答
  •  失恋的感觉
    2021-01-31 16:37

    Your checkLogin function is being called on another thread, so you need to switch back to the main thread before you can call self.performSegueWithIdentifier. I prefer to use NSOperationQueue:

    func checkLogin(succeed: Bool, msg: String) {
        if (succeed) {
            NSOperationQueue.mainQueue().addOperationWithBlock {
                self.performSegueWithIdentifier("logInTrue", sender: self)
            }        
        }
    }
    

    Alternate: xCode 10.1 1/2019

    func checkLogin(succeed: Bool, msg: String) {
        if (succeed) {
            OperationQueue.main.addOperation {
                self.performSegue(withIdentifier: "logInTrue", sender: self)
               }        
          }
     }
    

提交回复
热议问题