从谷歌帐户登录时如何转到其他视图控制器? (如果可能的话)(快速3)

时间:2016-10-02 02:32:29

标签: swift3 google-signin

我这样做了:" SecondViewController"是我想去的视图控制器:

func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "idSegueContent" {
        secondViewController = segue.destinationViewController as! SecondViewController //Error is here
    }
}

public func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
    if (error) != nil {
        print(error)
    }
    else {
        performSegue(withIdentifier: "idSegueContent", sender: self)
    }
}


func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) {
    if let err = error {
        print(error)
    } 

    SecondViewController.dismissViewControllerAnimated(true, completion: nil)
    //Error is here too
}

我正在尝试使用Gmail帐户登录,并在用户登录时在其他页面中显示用户信息。

1 个答案:

答案 0 :(得分:-1)

您可以添加此代码,以帮助您导航到其他ViewController

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!)  {
     if error != nil
    {
        print(error ?? "google error")
        return
    }
    let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let newViewController = storyBoard.instantiateViewController(withIdentifier: "navigation") as! NavigationController

   self.present(newViewController, animated: false, completion: nil)

//  lblUserName.text =  user.profile.email
}
相关问题