【发布时间】:2020-06-15 13:16:55
【问题描述】:
我将自定义类分配给导航栏,但导航栏上没有出现右键。 这是代码,如果有人可以提供帮助,将不胜感激。
class BaseNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationBar.tintColor = UIColor.white
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
navigationItem.leftBarButtonItem?.tintColor = UIColor.white
navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "contact_us"), style: .plain, target: self, action: #selector(callSupport))
self.navigationBar.barTintColor = UIColor(hexString: "#37C54D")
self.navigationBar.isTranslucent = true
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@objc func callSupport() {
print("Button Pressed")
}
}
【问题讨论】:
-
您应该在 viewController 而不是 navigationController 中设置 rightBarButtonItem。
-
因此我必须在 50 个视图控制器中添加该按钮。还有其他解决方案吗?
-
你可以创建一个 BaseViewController -> 设置 rightBarButtonItem 并且所有的 ViewController 都会继承它
-
任何示例以及我将在哪里分配基本视图控制器?
标签: ios swift uinavigationbar uinavigationitem