gpt4 book ai didi

uinavigationbar - 在 iOS8 Swift 中更改 UINavigationBar 标题

转载 作者:IT王子 更新时间:2023-10-29 05:45:48 27 4
gpt4 key购买 nike

我在我的名为 BaseViewController 的 Superview 中以编程方式添加了 UINavigationBar,它继承了 UIViewController。但是当我尝试为 UINavigationBar 设置标题时。我收到名为fatal error: Can't unwrap Optional.None

的错误

下面是我的swift类(class)。如何展开和更改 UINavigationBar 标题

import UIKit

class BaseViewConroller: UIViewController {
var navBar:UINavigationBar=UINavigationBar()

override func viewDidLoad() {
super.viewDidLoad()
setNavBarToTheView()
// Do any additional setup after loading the view.
navBar.topItem.title="test test"
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func setNavBarToTheView()
{
navBar.frame=CGRectMake(0, 0, 320, 50)
navBar.backgroundColor=(UIColor .blackColor())
self.view .addSubview(navBar)
}

}

最佳答案

将您的 navBar.topItem.title="test test" 替换为 self.title="test test"。干杯!!

关于uinavigationbar - 在 iOS8 Swift 中更改 UINavigationBar 标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24383068/

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