gpt4 book ai didi

ios - Swift:谷歌登录后转到其他 View Controller

转载 作者:行者123 更新时间:2023-11-28 11:36:29 25 4
gpt4 key购买 nike

用户成功登录后,我希望屏幕自动显示选项卡 Controller View 。

现在我完成了集成 Google 登录部分。但登录后, View 返回到初始 View Controller 。

我的 Storyboard看起来像这样,初始 View Controller 中的蓝色 View 是 Google 登录按钮。

下面是我的 didSignInFor 函数:

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!,
withError error: Error!) {
if let error = error {
print("\(error.localizedDescription)")
} else {
//...
}
}

我知道我应该在 else{} 中添加代码,但仍然不确定该怎么做。

感谢您的帮助!

最佳答案

对于你的情况,首先你需要为你的 UITabBarController 创建一个类,这将确认 UITabBarController 而不是 UIViewController 是这样的:

class TabBarConroller: UITabBarController {

TabBarConroller 是您的新 .swift 文件。现在转到您的 Storyboard并单击您的 TabBarController 并单击 Identity Inspector 并将这个新创建的类分配给它。

接下来,如果用户使用以下代码成功验证,则需要启动该类:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tabbarVC = storyboard.instantiateViewController(withIdentifier: "TabbarIdentifier") as! UITabbarController
self.present(tabbarVC, animated: false, completion: nil)

您还需要在 Identity Inspector 的 Storyboard ID 中分配一件事,即 TabbarIdentifier

因此您的代码将如下所示:

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!,
withError error: Error!) {
if let error = error {
print("\(error.localizedDescription)")
} else {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tabbarVC = storyboard.instantiateViewController(withIdentifier: "TabbarIdentifier") as! UITabbarController
self.present(tabbarVC, animated: false, completion: nil)
}
}

关于ios - Swift:谷歌登录后转到其他 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55215761/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com