gpt4 book ai didi

ios - 如何更改 UINavigationController Title & backButton 编程?

转载 作者:行者123 更新时间:2023-11-28 15:48:29 27 4
gpt4 key购买 nike

我有两个 View Controller 。

vc1 -> presentVC -> vc2

vc2继承UINavigationController

我想在 vc2 中设置 title 和 backButton,但是它不起作用。

class vc2: UINavigationController {

override func viewDidLoad() {
super.viewDidLoad()

// set title!!!
//self.navigationItem.title = "123"
//self.navigationController?.navigationBar.topItem?.title = "123"
//self.title = "123"
//self.navigationBar.topItem?.title = "123"
//self.navigationItem.title = "123"

// set backButton!!!
let navButtonWidth:CGFloat = 44
let backButton:UIButton = UIButton()
backButton.setImage(backImage, for: .normal)
backButton.addTarget(self, action: #selector(back), for: .touchUpInside)
self.navigationItem.leftBarButtonItems = [UIBarButtonItem(customView: backButton)]

}

最佳答案

将下面的代码放在 perform(segue)viewWillDissappear 中,具体取决于您如何进行演示 - 通过 Storyboard segue 或手动从代码。

let backButton = UIBarButtonItem()
backButton.title = "whatever_you_want"
navigationItem.backBarButtonItem = backButton

并且在你的vc2viewDidLoad中简单的说

navigationItem.title = "Controller title"

关于ios - 如何更改 UINavigationController Title & backButton 编程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42619673/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com