繁体   English   中英

使用 Tab Bar Controller Swift 在导航栏中添加新的栏按钮

[英]Add new bar button in Navigation Bar with a Tab Bar Controller Swift

我在 swift 3 中有下一个结构:

导航控制器 -> 标签栏控制器 -> 4 个视图控制器

我有 3 个公共栏按钮项目。 我的问题是,仅在其中一个视图控制器中,我想在右上角添加新的栏按钮项。 这样,当我导航到其他视图时,不应出现新按钮。

我该如何解决这个问题?

谢谢!

您应该在Swift 中像这样使用tabBarController设置它:

let button = UIButton(type: .custom)
button.setImage(UIImage(named: "imageName"), for: .normal)
button.addTarget(self, action: #selector(buttonClicked), for: .touchUpInside)
let leftButtonBar = UIBarButtonItem(customView: button)
tabBarController?.navigationItem.rightBarButtonItems = [leftButtonBar]. 

这是永远的最佳答案并且可以正常工作。

您可以拥有以下结构,通过该结构您可以拥有单独的导航来为每个视图控制器添加按钮

Tab Bar Controller ->Navigation Controller -> 1st View Controllers
                    ->Navigation Controller -> 2nd View Controllers
                    ->Navigation Controller -> 3rd View Controllers
                    ->Navigation Controller -> 4th View Controllers

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM