Swift segue不工作? [英] Swift segue not working?
问题描述
我的Swift segue根本没有工作,没有发生任何错误。断点显示我的应用程序落在这条线上,但没有任何反应:
self.performSegueWithIdentifier(SignupSegue,sender:self )
代码块是与Facebook的登录表单:
pre>
如果让accessToken:FBSDKAccessToken = FBSDKAccessToken.currentAccessToken(){
PFFacebookUtils.logInInBackgroundWithAccessToken(result.token,block:{
(user:PFUser? ,错误:NSError?) - > Void in
如果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
的块仍处于后台状态。也许在 dispatch_async(dispatch_get_main_queue(),{})
中触发 showViewController
,看看是否有任何差异。 p
dispatch_async(dispatch_get_main_queue(),{
let storyboard:UIStoryboard = UIStoryboard(name:Main,bundle:nil)
let vc = storyboard.instantiateViewControllerWithIdentifier(SignUpViewController)
self.showViewController(vc,sender:self)
})
My Swift segue is not working at all and isn't throwing any errors. The breakpoint shows me that the app lands on this line but nothing happens:
self.performSegueWithIdentifier("SignupSegue", sender: self)
The code block is a login form with 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)
}
})
}
Here's the segue function it should call, but doesn't even get to it:
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)
}
}
Any ideas?
Generally, any UI updating has to be in main thread. I think the block for PFFacebookUtils.logInInBackgroundWithAccessToken
is still in the background state in above situation. Maybe trigger the showViewController
in dispatch_async(dispatch_get_main_queue(), {})
and see if there is any difference.
dispatch_async(dispatch_get_main_queue(), {
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("SignUpViewController")
self.showViewController(vc, sender: self)
})
这篇关于Swift segue不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!