gpt4 book ai didi

swift - VC 使用 self.present 调用时不显示 navigationItem

转载 作者:行者123 更新时间:2023-11-28 05:59:46 29 4
gpt4 key购买 nike

在这方面需要帮助,因为我已经苦苦挣扎了几天......

我有一个带有从 viewDiDLoad 调用的导航项的 VC:

override func viewDidLoad() {
super.viewDidLoad()
self.customization()
self.fetchData()
}

...

func customization() {
self.navigationItem.title = self.currentUser?.displayName
self.navigationItem.setHidesBackButton(true, animated: false)
let icon = UIImage.init(named: "back")?.withRenderingMode(.alwaysTemplate)
let backButton = UIBarButtonItem.init(image: icon!, style: .plain, target: self, action: #selector(self.dismissSelf))
backButton.tintColor = UIColor(red: 0.0157, green: 0.498, blue: 0, alpha: 1.0)
self.navigationItem.leftBarButtonItem = backButton
self.locationManager.delegate = self
print("called customization()")
}

当使用触发的 segue Show 调用时,这可以完美无缺地工作。

当我用下面的代码调用 VC 时:

    let storyBoard: UIStoryboard = UIStoryboard(name: "Storyboard", bundle: nil)
let viewController = storyBoard.instantiateViewController(withIdentifier: "SecondVC") as! SecondVC
self.present(viewController, animated: true, completion: nil)

我从控制台获得了访问 viewDidLoad 和 customizations() 的方法:

called customization() 

但是 navigationItem 没有显示。

试图从调用方法中复制 customization() 中的方法,它们被执行但也没有显示。

知道这里出了什么问题吗?

最佳答案

演示时必须添加导航:

let storyBoard: UIStoryboard = UIStoryboard(name: "Storyboard", bundle: nil)
let viewController = storyBoard.instantiateViewController(withIdentifier: "SecondVC") as! SecondVC
let nav = UINavigationController(rootViewController: viewController)
self.present(nav, animated: true, completion: nil)

关于swift - VC 使用 self.present 调用时不显示 navigationItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50189437/

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