[英]Large Titles Not Being Set Via Extension [Swift 5]
I have an extension to configure my UINavigationController
with large titles which I call in ViewDidLoad
of my controller;我有一个扩展来配置我的
UINavigationController
与我在控制器的ViewDidLoad
中调用的大标题;
extension UINavigationController {
func configure(with title: String) {
navigationController?.navigationBar.prefersLargeTitles = true
navigationItem.title = title
navigationItem.largeTitleDisplayMode = .automatic
}
}
This extension doesn't seem to be called, however, when I place:但是,当我放置以下内容时,似乎没有调用此扩展程序:
navigationController?.navigationBar.prefersLargeTitles = true
Into my ViewDidLoad
, it works as expected.进入我的
ViewDidLoad
,它按预期工作。 any ideas on why this would be?关于为什么会这样的任何想法?
When you call navigationController?.navigationBar.prefersLargeTitles = true
it refers to ViewController.navigationController
.当您调用
navigationController?.navigationBar.prefersLargeTitles = true
它指的是ViewController.navigationController
。
But your extension is for UINavigationController
so it refers ViewController.navigationController.navigationController
但是你的扩展是用于
UINavigationController
所以它指的是ViewController.navigationController.navigationController
Just replace this:只需替换这个:
navigationController?.navigationBar.prefersLargeTitles = true
With this:有了这个:
navigationBar.prefersLargeTitles = true
and call this in viewDidLoad
:并在
viewDidLoad
调用它:
navigationController?.configure(with: "")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.