gpt4 book ai didi

ios - 从 ViewController 转换到 SelectedIndex 处的选项卡

转载 作者:行者123 更新时间:2023-11-30 13:15:38 24 4
gpt4 key购买 nike

我试图从 tabviewcontroller 之外的 View Controller 的特定索引处显示 tabviewcontroller。

例如,我有这样的代码:

let tabBar = self.storyboard?.instantiateViewController(withIdentifier: "TabBar")
self.show(tabBar!, sender: self)

此代码在第一个索引处显示 tabviewcontroller。但是当我尝试在选项卡 View 中选择某个索引并隐藏选项卡栏时,它会崩溃。
所以我尝试了以下方法:

tabBarController?.tabBar.isHidden = true
tabBarController?.selectedIndex = 3

当原始 View Controller 位于 tabbarcontroller 中时,它可以工作。但是,当我将 View Controller 移到 tabbarcontroller 之外时,它不起作用。

我希望能够从外部 View Controller 显示选项卡 View Controller 的特定索引并隐藏选项卡栏。

干杯

最佳答案

let tabbar = self.storyboard?.instantiateViewController(withIdentifier: "TabBar") as? UITabBarController
tabbar?.selectedIndex = 2
tabbar?.tabBar.isHidden = true
self.show(tabbar!, sender: self)

关于ios - 从 ViewController 转换到 SelectedIndex 处的选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38268887/

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