简体   繁体   English

Swift:如何隐藏标签栏控制器的第一个视图控制器上的后退按钮?

[英]Swift: how to hide back button on the first view controllers of tab bar controller?

My Tab Bar Controller controls 5 view controllers and I want that in those 5 main pages all the back buttons are disabled and not visible. 我的标签栏控制器控制5个视图控制器,我希望在这5个主页面中,所有后退按钮都被禁用且不可见。 How can I do that correctly? 我怎么能正确地做到这一点? I have tried all Swift commands seen here in SO but none has worked up to now. 我已经尝试过在这里看到的所有Swift命令,但是到目前为止还没有完成。

在此输入图像描述

I have tried with 我试过了

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationItem.hidesBackButton = true
}

override func viewWillAppear(animated: Bool) {
    self.navigationItem.hidesBackButton = true
}

but they don't work. 但他们不起作用。 I have also tried with 我也尝试过

self.tabBarController?.navigationItem.hidesBackButton = true

but this is the strange result 但这是奇怪的结果

在此输入图像描述

To remove the "back" button from the navigation bar, you can create a UITabBarController class for your UITabBarController in the storyboard, and in that class, inside the ViewDidLoad() method, you can call 要从导航栏中删除“后退”按钮,可以在故事板中为UITabBarController创建一个UITabBarController类,在该类中,在ViewDidLoad()方法中,您可以调用

self.navigationItem.hidesBackButton = true 

This will remove the back button. 这将删除后退按钮。

The back button is probably added by the navigationcontroller of the tabbarcontroller . 后退按钮可能由tabbarcontrollernavigationcontroller添加。 So you will have to check the tabbar navigation controller. 所以你必须检查标签栏导航控制器。

Something like this: 像这样的东西:

self.tabbarcontroller.navigationcontroller.navigationitem.hidesBackButton = true

I think this will resolve the issue. 我认为这将解决这个问题。 Since the backbutton normally is added by a navigationcontroller , and not by a tabbarcontroller 由于后退按钮通常由导航 控制器添加,而不是由tabbarcontroller添加

Update 更新

I have recommended him that he should loose the navigation controllers after the tabbarcontroller. 我建议他在tabbarcontroller之后松开导航控制器。 Since the tabbar already implements the navigation needed between the different views. 由于tabbar已经实现了不同视图之间所需的导航。 This and hidesbackbutton = true solved his issue 这和hidesbackbutton = true解决了他的问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在标签栏控制器中快速隐藏视图控制器? - how hide a view controller in tab bar controller swift? 如何快速隐藏嵌入在导航堆栈中的视图控制器中的选项卡栏? - how to hide tab bar in the view controller that embedded in the navigation stack in swift? 如何快速隐藏导航控制器中的后退栏按钮 - How hide back bar button in navigation controller with swift 如何在标签栏 Controller 视图上创建后退按钮? - How can I create a back button on a Tab Bar Controller view? 如何通过单击按钮功能快速调用标签栏视图控制器 - how to call tab bar view controller by click button function in swift 如何强制后退按钮转到第一个视图控制器(快速) - How to Force Back Button to Go to First View Controller (swift) Swift:在XLPagerTabStrip中使用子视图控制器后,如何选择回到第一个视图控制器 - Swift: How to segue back to first view controller after using child view controllers from the XLPagerTabStrip Swift如何正确使用关闭视图控制器/如何使用3个视图控制器制作后退按钮 - Swift How to use dismiss view controller properly/ How to make a back button with 3 View Controllers 尝试创建导航栏后退按钮到选项卡栏控制器视图 - Trying to create a Navigation Bar back button to a Tab Bar Controller view 如何隐藏带有其他视图控制器的标签栏视图控制器? - How to hide a tab bar view controller with another view controller over it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM