gpt4 book ai didi

swift - NavigationItem 右键未设置

转载 作者:行者123 更新时间:2023-11-28 12:22:35 27 4
gpt4 key购买 nike

我失去了在我的自定义导航 Controller 上设置右键的想法。

我的类扩展了 UINavigationCOntroller。我清理了所有内容,然后在 viewDidAppear 上运行以下代码。

navigationBar.topItem?.title = "Carpool"

let languagesSpinner = UIBarButtonItem(title: "PT", style: .done, target: self, action: #selector(didClickLanguagesButton))
navigationItem.setRightBarButton(languagesSpinner, animated: true)

设置了标题,但没有设置按钮。

奇怪的是,我用po调试的时候就设置了这个项目。

谁能帮帮我?

最佳答案

您正在使用 navigationBar.topItem 设置 title 并使用 navigationItem 设置 rightBarButton 所以尝试设置 rightBarButton 也与 navigationBar.topItem

尝试一次

navigationBar.topItem?.setRightBarButton(languagesSpinner, animated: true)

代替

navigationItem.setRightBarButton(languagesSpinner, animated: true) 

关于swift - NavigationItem 右键未设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44368633/

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