ios - swift ios 无法更改导航栏标题

标签 ios swift xcode uinavigationcontroller uinavigationitem

我有一个模态 VC,我已经使用 Storyboard 拖入了导航栏:

enter image description here

但现在我只能在 Storyboard 中更改标题,而不能在代码中更改。我需要能够在代码中更改它,因为标题是动态的。

这两个我都试过了:

self.title = "some title"

navigationBar.topItem.title = "some title"

但它们都不起作用,我也没有收到任何警告/错误

最佳答案

如果您的 NavigationBar 通过 Outlet 连接到您的 ViewController,则可以正常工作:

class ViewController: UIViewController {

    @IBOutlet weak var navigationbar: UINavigationBar!

    override func viewDidLoad() {
        super.viewDidLoad()

        navigationbar.topItem!.title = "Dynamic"
    }

}

关于ios - swift ios 无法更改导航栏标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38882455/

相关文章:

ios - 修复静态 tableviewcontroller xcode 8 中 Storyboard 中的所有警告

ios - 白标企业 iOS 应用程序

xcode - 未正确添加文件夹到Xcode项目

swift - swift 3.0 中的 dispatch_group_async 函数

swift - swift 中带有可选变量的冗余 - 是否有优雅的解决方案?

xcode - Swift 脚本自动完成

ios - 限制 FlipsideViewController 方向

ios - 如何将 NSMutableArray 保存到本地存储

ios - 在 swift 2 中调用和打印对象内部的对象

ios - 推送基于 swift 的应用程序所需的 Xcode 版本