【问题标题】:NavigationBar Right Button is not AppearingNavigationBar 右按钮未出现
【发布时间】: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


【解决方案1】:

@Muhammad Hasan Irshad
基础视图控制器:

一个示例 ViewController:

【讨论】:

  • 感谢指导,但都是一样的,需要分配50个vc。
猜你喜欢
  • 2018-12-11
  • 2018-06-11
  • 2011-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-10
  • 1970-01-01
相关资源
最近更新 更多