[英]performSegueWithIdentifier from NSURLSession
我正在嘗試找到一種適當的方法來遍歷NSURLSession中的數據以創建User對象。
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { data, response, error -> Void in
if error != nil {
print("Something went wrong: \(error)")
return
}
self.handleLoginAttempt(data!)
print("Finished Login Attempt!")
}
task.resume()
func handleLoginAttempt(data: NSData) {
// Iterate through data.
self.performSegueWithIdentifier("LoggedInSuccessfully", sender: nil)
}
現在,它可以正確轉到下一個View控制器,但是只是掛起了。 如您所見,我在viewDidLoad()
的末尾將打印語句( print("Finished Login Attempt!")
)放在末尾,我從新ViewController的viewDidLoad中看到該語句,但從未看到“ Finished Login Attempt”。 因此,假設這可能是應用程序的相當基本的操作,那么我假設我做的NSURLSession不正確。
干杯
嘗試在MainThread上運行
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.handleLoginAttempt(data!)
print("Finished Login Attempt!")
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.