waitUntilAllTasksAreFinished error Swift

前端 未结 4 1439
抹茶落季
抹茶落季 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)
               }        
          }
     }
    
    0 讨论(0)
  • 2021-01-31 16:50

    I was also having same issue, got resolved by taking reference from above answer. Thank you @Nate

    var storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    var vc: UINavigationController = storyBoard.instantiateViewControllerWithIdentifier("AppViewController") as! UINavigationController
    
    NSOperationQueue.mainQueue().addOperationWithBlock {
        self.presentViewController(vc, animated: true, completion: nil)
    }
    
    0 讨论(0)
  • 2021-01-31 16:55

    With Xcode 8.0 and Swift 3, this has been modified to the following construct:

    OperationQueue.main.addOperation{
        <your segue or function call>
    }
    
    0 讨论(0)
  • 2021-01-31 16:58

    I was having this issue when trying to change the contents of a text box from inside an Async Task.

    The solution was using the DispatchQueue (Xcode 8.0 and Swift 3.0):

        DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
           self.textBox.text = "Some Value"
           }
    
    0 讨论(0)
提交回复
热议问题