繁体   English   中英

未在TabBarController中嵌入的navigationBar中显示按钮项目

[英]Button item not shown in navigationBar embebed in TabBarController

我正在开发一个应用程序,其中viewController嵌入在navigationBar中,而这个navigationBar嵌入在TabBarViewController中。

在我的应用中,我有2个不同的标签(目前),其中一个标签是“活动视图”。 这是一个带有tableView的listController的viewController。 每个单元格都将显示相同的视图控制器,并在触摸时显示详细信息活动。

我的问题是没有显示带有按钮的navigationItem。

我正在尝试以下解决方案: 导航栏上未显示Bar按钮项 ,因为我的问题非常相似,但是没有用。

故事板和应用程序运行的一些屏幕截图: 故事板 应用程序在没有按钮的情况下运行

我正在尝试以编程方式添加按钮,但没有结果:

var logoutButton: UIBarButtonItem!
var filterButton: UIBarButtonItem!


//MARK: - Lyfe cycle
override func viewDidLoad() {
super.viewDidLoad()

let logoutImage = UIImage(named: "logout-24")
let filterImage = UIImage(named: "filterOutline-24")

logoutButton = UIBarButtonItem(image: logoutImage, style: .Plain, target: self, action: "logoutAction:")
filterButton = UIBarButtonItem(image: filterImage, style: .Plain, target: self, action: "filterAction:")
navigationItem.rightBarButtonItems = [filterButton, logoutButton]

检查您的图像。 我看不到您的代码有任何问题。 或者您可以尝试仅添加如下标题

logoutButton = UIBarButtonItem(title: "Log out", style: .Plain, target: self, action:Selector("logoutAction:"))
filterButton = UIBarButtonItem(title: "Filter", style: .Plain, target: self, action: Selector("filterAction:"))

如果显示按钮栏。 我确定问题出在你的形象上。

我也遇到了类似的问题,后来我发现可以在选项卡栏控制器本身中设置导航栏,而无需在视图控制器中进行设置

let profilePutton = UIButton(type: .custom)
profilePutton.setTitle("Profile", for: .normal)
profilePutton.frame = CGRect(x: 0.0, y: 0.0, width: 30.0, height: 30.0)
profilePutton.addTarget(self, action: #selector(openProfilePage), for: .touchUpInside)
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: profilePutton)

对于Tabar应用程序,我们应该这样添加,

 let logoutButton = UIBarButtonItem(image: UIImage(named: "ic_logout"), style: .plain, target: self, action:#selector(logoutButtonTapped))    
 self.tabBarController?.navigationItem.leftBarButtonItem = logoutButton

 let nightModeButton = UIBarButtonItem(image: UIImage(named: "ic_night_mode_off"), style: .plain, target: self, action:#selector(nightModeButoonTapped))
 self.tabBarController?.navigationItem.rightBarButtonItem  = nightModeButton

暂无
暂无

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

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