我的 Swift segue 根本不工作,也没有抛出任何错误。断点向我显示应用程序位于这一行但没有任何反应:
self.performSegueWithIdentifier("SignupSegue", sender: self)
代码块是 Facebook 的登录表单:
if let accessToken: FBSDKAccessToken = FBSDKAccessToken.currentAccessToken() {
PFFacebookUtils.logInInBackgroundWithAccessToken(result.token, block: {
(user: PFUser ? , error : NSError ? ) - > Void in
if user!.isNew {
self.performSegueWithIdentifier("SignupSegue", sender: self)
} else {
self.navigateToInGame(true)
}
})
}
这是它应该调用的 segue 函数,但甚至没有调用它:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
if (segue.identifier == "SignupSegue") {
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("SignUpViewController")
self.showViewController(vc, sender: self)
}
}
有什么想法吗?
最佳答案
通常,任何 UI 更新都必须在主线程中进行。我认为 PFFacebookUtils.logInInBackgroundWithAccessToken
block 在上述情况下仍处于后台状态。也许触发 dispatch_async(dispatch_get_main_queue(), {})
中的 showViewController
看看是否有什么不同。
dispatch_async(dispatch_get_main_queue(), {
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("SignUpViewController")
self.showViewController(vc, sender: self)
})
关于ios - Swift segue 不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35953021/