如何在导航栏,标签栏,视图控制器之间传递数据

问题描述 投票:0回答:1

我首先使用GoogleSignIn SDK作为登录短语。然后,我使用以下代码重定向到我的应用程序的主页。self.present(tabController, animated: true, completion: nil)

这是我的应用程序的结构(我使用情节提要):

TabBarController

  1. NavigationBarController(主页):视图控制器
  2. NavigationBarController(功能1):视图控制器
  3. NavigationBarController(功能2):视图控制器
  4. NavigationBarController(配置文件):视图控制器

现在,我已经登录,我想将数据从Google传递到我的个人资料根视图控制器。但是,我不确定该怎么做。

这是我当前的代码,我已经在其中输入了func符号(_ signIn:GIDSignIn !, didSignInFor用户:GIDGoogleUser!,withError错误:Error!):

let tabController: UITabBarController = self.storyboard?.instantiateViewController(withIdentifier: "homepageVC") as! UITabBarController
        let navController: UINavigationController = self.storyboard?.instantiateViewController(withIdentifier: "homepageVC2") as! UINavigationController
        let vc = navController.viewControllers[0] as! ViewController

        tabController.modalPresentationStyle = .fullScreen
        vc.name = fullName
        self.present(tabController, animated: true, completion: nil)

**其中fullName是我的LoginViewController中的全局变量,其中包含user.fullName(来自google)。

但是,因为它不起作用。我希望有人可以帮助我解决这个问题。非常感谢。

ios swift uinavigationcontroller uitabbarcontroller viewcontroller
1个回答
0
投票

[我在这里使用Firebase之类的产品进行登录的操作,

创建一个为用户处理所有数据的类

class UserClass: {
   static var name: String = ""
   static var email: String = ""
   static var UID: String = ""
   static var youGetTheIdea: String = ""
   static var some_array: [String] = [""]

}

您先致电,然后通过UserClass.name从任何班级致电此>

[您可能想读一读,以获得更多带有正确解释的选项

https://learnappmaking.com/pass-data-between-view-controllers-swift-how-to/

© www.soinside.com 2019 - 2024. All rights reserved.