[英]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 . 后退按钮可能由tabbarcontroller的navigationcontroller添加。 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.