我想在我的项目中集成导航 Controller 和标签栏 Controller 。但是我无法将右栏按钮添加到导航 Controller 。
我所做的是将导航 Controller 添加到登录屏幕,这次我可以通过添加代码以及将 barbuttonitem 拖动到导航 Controller 来添加 barbuttonitem。
let addBtn = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addTapped))
self.navigationItem.rightBarButtonItem = addBtn
我面临的问题是在添加选项卡栏 Controller 后,我无法通过代码以及拖动到导航 Controller 来添加右栏按钮。请帮助我。
最佳答案
当 ViewController 嵌入到您使用的 NavigationController 中时
self.navigationItem.rightBarButtonItem = addBtn
在您的项目中,Detail Screen 没有直接嵌入到 NavigationController 中。 Detail Screen嵌入TabBarController,TabBarController嵌入NavigationController。所以你应该使用
self.tabBarController?.navigationItem.rightBarButtonItem = addBtn
但是这个 addBtn 将在嵌入到 TabBarController 中的所有 View Controller 中可见。
如果您只想为一个 View Controller 添加 rightBarButton,则将详细信息屏幕嵌入到新的 NavigationController 中。然后你可以添加 rightBarButton 使用
self.navigationItem.rightBarButtonItem = addBtn
关于ios - 无法将 barbuttonitem 添加到导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56015775/