我正在使用Xcode 11.2.1,Swift 5,并具有以模态形式显示的视图。通过情节提要,我添加了一个导航栏,并具有两个导航项,左,取消,右,保存。我正在尝试显示视图的标题。我已经尝试过通过viewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.title = "New " + costumeChoice
imageFromFileButton.alpha = 0.5
imageFromFileButton.isEnabled = false
costumeImageView.image = UIImage(named: "PauPlaceholder")
}
我通过viewWillAppear和viewDidAppear尝试过“ self.navigationItem.title =” New“ +服装选择,但没有运气。
我想念什么?
您必须提供一个嵌入了ViewController的NavigationController,这样将显示一个NavigationBar。例如:
假设您当前的ViewController是CurrentViewController
和您要显示的viewController是DestinationViewController
为了显示destinationController,您必须执行以下操作:-
// self ==> CurrentViewController
self.present(UINavigationController(rootViewController:DestinationViewController(), animated: true)