Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在tabbar控制器中设置rootview,并在swift ios中的每个视图控制器中显示tabbar?_Ios_Swift3_Uitabbarcontroller - Fatal编程技术网

如何在tabbar控制器中设置rootview,并在swift ios中的每个视图控制器中显示tabbar?

如何在tabbar控制器中设置rootview,并在swift ios中的每个视图控制器中显示tabbar?,ios,swift3,uitabbarcontroller,Ios,Swift3,Uitabbarcontroller,我不熟悉斯威夫特。我已经在appdelegate中配置了选项卡栏控制器。现在我需要在这里设置rootview控制器,并且需要在我声明的所有ViewController中显示选项卡栏 这对你有帮助。尝试在选项卡栏控制器内部设置导航。为导航控制器提供选项卡栏项。比如: 输出为: 按下按钮时: 这将对您有所帮助。尝试在选项卡栏控制器内部设置导航。为导航控制器提供选项卡栏项。比如: 输出为: 按下按钮时: 您可以使用Xib创建如下所示的tabbarcontroller func applicat

我不熟悉斯威夫特。我已经在appdelegate中配置了选项卡栏控制器。现在我需要在这里设置rootview控制器,并且需要在我声明的所有ViewController中显示选项卡栏

这对你有帮助。尝试在选项卡栏控制器内部设置导航。为导航控制器提供选项卡栏项。比如:

输出为:

按下按钮时:


这将对您有所帮助。尝试在选项卡栏控制器内部设置导航。为导航控制器提供选项卡栏项。比如:

输出为:

按下按钮时:


您可以使用Xib创建如下所示的tabbarcontroller

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    self.window = UIWindow(frame: UIScreen.main.bounds)
    self.window?.backgroundColor = UIColor.white

    let tabBarController = self.window!.rootViewController as! UITabBarController
    let tabBar = tabBarController.tabBar as UITabBar


    let tabBarItem0 = tabBar.items![0] as! UITabBarItem
    let tabBarItem1 = tabBar.items![1] as! UITabBarItem
    let tabBarItem2 = tabBar.items![2] as! UITabBarItem
    let tabBarItem3 = tabBar.items![3] as! UITabBarItem

            tabBar.barTintColor = UIColor(red: 0.0, green: 122.0/255.0, blue: 1.0, alpha: 1.0)

    tabBarItem0.title = "Home"
    tabBarItem1.title = "Search"
    tabBarItem2.title = "User"

您可以使用Xib创建如下所示的tabbarcontroller

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    self.window = UIWindow(frame: UIScreen.main.bounds)
    self.window?.backgroundColor = UIColor.white

    let tabBarController = self.window!.rootViewController as! UITabBarController
    let tabBar = tabBarController.tabBar as UITabBar


    let tabBarItem0 = tabBar.items![0] as! UITabBarItem
    let tabBarItem1 = tabBar.items![1] as! UITabBarItem
    let tabBarItem2 = tabBar.items![2] as! UITabBarItem
    let tabBarItem3 = tabBar.items![3] as! UITabBarItem

            tabBar.barTintColor = UIColor(red: 0.0, green: 122.0/255.0, blue: 1.0, alpha: 1.0)

    tabBarItem0.title = "Home"
    tabBarItem1.title = "Search"
    tabBarItem2.title = "User"

根据我的理解,你想要实现这样的目标:

UITabBarController
-->对于每个选项卡,将有一个
导航控制器
,其根目录将是一个具有选项卡栏的
VC

因此,我建议您直接为
导航控制器
的每个根目录使用
uitabarcontroller

这意味着您的根目录将是
UITabBarController
,然后对于每个
选项卡
将有
UINavigationController
,其第一个
视图控制器
将再次成为
UITabBarController

欲了解更多信息,请参见下图。它仅显示
UITabBarController
的一个选项卡的流程。对所有其他
选项卡重复相同的操作


根据我的理解,您希望实现以下目标:

UITabBarController
-->对于每个选项卡,将有一个
导航控制器
,其根目录将是一个具有选项卡栏的
VC

因此,我建议您直接为
导航控制器
的每个根目录使用
uitabarcontroller

这意味着您的根目录将是
UITabBarController
,然后对于每个
选项卡
将有
UINavigationController
,其第一个
视图控制器
将再次成为
UITabBarController

欲了解更多信息,请参见下图。它仅显示
UITabBarController
的一个选项卡的流程。对所有其他
选项卡重复相同的操作


为什么不使用故事板?@Amanpreet。我已经开始使用xib。你能帮忙吗?最好是用情节提要。“我将给你一个如何实现的方案。”Amanpret。请尽量理解。我需要让它在xib中工作。你能帮我吗?好的。看看这个。它会帮助你:为什么不使用故事板?@Amanpreet。我已经开始使用xib。你能帮忙吗?最好是用情节提要。“我将给你一个如何实现的方案。”Amanpret。请尽量理解。我需要让它在xib中工作。你能帮我吗?好的。看看这个。它将帮助您: