我已经阅读了多篇关于此的帖子,但无法使其正常运行。
我已经读过的帖子:
我在ViewController-A
中嵌入了UINavigationController
。控制器的navigation bar
包含rightBarButtonItem
。添加rightBarButtonItem
的代码:
let searchButton = UIBarButtonItem(image: UIImage(named: "HomeSearch"), style: .plain, target: self, action: #selector(navigateToSearchScreen))
self.navigationItem.rightBarButtonItem = searchButton
当另一个ViewController-B
被推入导航堆栈并弹回时,rightBarButtonItem
将从导航栏中消失。
答案 0 :(得分:0)
我认为在nextViewcontroller中你隐藏了导航右栏,所以当你弹出然后导航按钮将不会显示所以你必须在viewWillAppear
中添加右栏按钮:
override func viewWillAppear(_ animated: Bool) {
let searchButton = UIBarButtonItem(image: UIImage(named: "HomeSearch"), style: .plain, target: self, action: #selector(navigateToSearchScreen))
self.navigationItem.rightBarButtonItem = searchButton
}