我目前正在尝试使用条件语句来使用performSegue(withIdentifier:sender:)
。目前,我没有收到错误,但没有执行segue。该项目正在使用Facebooks SDK,因此当用户登录时会调用loginButton()
(此部分有效,控制台打印"用户登录"如果正常运行则确认SDK)
标识符在故事板中拼写正确
class LoginViewController: UIViewController, FBSDKLoginButtonDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let loginButton = FBSDKLoginButton()
loginButton.frame = CGRect(x: 15, y: view.frame.maxY - 50, width: view.frame.width - 32, height: 32)
view.addSubview(loginButton)
loginButton.delegate = self
}
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!)
{
if error != nil
{
print(error)
return
}
else
{
print("user is logged in")
}
performSegue(withIdentifier: "postToView", sender: self)
}
func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!)
{
print("logged out")
}
}
如果条件为真,我怎样才能让它执行segue?
答案 0 :(得分:-1)
将loginButton()中的segue调用替换为。
DispatchQueue.main.async {
[unowned self] in
self.performSegueWithIdentifier("postToView", sender: self)
}