Ios 按下选项卡栏时隐藏视图-swift
我有一个视图控制器,如下所示 此视图附带了一个tabBarController。tabBarController有5个viewController,我必须从另一页展示tabBar的第5个viewController。因此,我现在使用下面的代码作为viewControllerIos 按下选项卡栏时隐藏视图-swift,ios,swift,uinavigationcontroller,uitabbarcontroller,tabbar,Ios,Swift,Uinavigationcontroller,Uitabbarcontroller,Tabbar,我有一个视图控制器,如下所示 此视图附带了一个tabBarController。tabBarController有5个viewController,我必须从另一页展示tabBar的第5个viewController。因此,我现在使用下面的代码作为viewController @IBAction func onClickUserProfile(_ sender: Any) { let navVc = self.storyboard?.instantiateViewControll
@IBAction func onClickUserProfile(_ sender: Any) {
let navVc = self.storyboard?.instantiateViewController(withIdentifier: "ProfileVC")as! ProfileVC
navVc.userId = Int(self.userId)
navVc.navigationItem.hidesBackButton = true
navVc.tabBarController?.tabBar.isHidden = false
self.navigationController?.pushViewController(nxtVc, animated: true)
}
但在执行代码后,它将生成视图控制器,如下图所示。
视图经过选项卡栏。有人帮我推到tabBar视图吗
您需要从
uitabarcontroller
设置所选的UIViewController
,类似的设置应该可以工作
self.tabBarController?.selectedViewController = self.tabBarController?.viewControllers![1]
其中tabBarController?.viewControllers
返回嵌入UITabBarController
的当前viewControllers
数组
你的代码应该是这样的
@IBAction func onClickUserProfile(_ sender: Any) {
let vc = self.tabBarController?.viewControllers![1] as! ProfileVC // use your index
vc.userId = Int(self.userId)
self.tabBarController?.selectedViewController = vc
}
注意:不要将UIViewController
的实例创建为。InstanceEviewController(标识符:)
使用已存在的
数组tabBarController?.viewControllers
中的,创建新的
实例将被视为新实例,并给出您遇到的问题
在那里
尝试将automaticallyAdjustsScrollViewInsets设置为false,在ProfileVC(viewDidLoad)中什么都不会发生。视图返回相同的结果为什么不使用present函数来显示视图控制器?使用present时,它隐藏了选项卡栏和导航栏“出售员工”按钮的底部约束是什么?