swift - 我可以从自定义视图类更改 NavigationController 设置吗
问题描述
我可以从自定义视图类更改 NavigationController 设置吗?
import UIKit
class TutorialView: UIView {
init() {
//change navigation controller settings
//ex: navigationController.navigationItem.title = "hoge"
}
}
我知道这种方式。但是我的应用程序 rootViewController 是 TabBarController。TabBarController 上的 NavigationController。
(window?.rootViewController as? UINavigationController)?.navigationItem.title = "hoge"
以什么方式最好更改 NavigationController 设置?
解决方案
ViewControllers
s viewDidLoad
Method 是更改 NavigationController 任何属性的正确位置,IMO,只要它们特定于该视图。这些包括标题颜色、大标题显示设置等...如果您想更改/添加 NavigationController 方法,例如实现新的 pushViewController 方法,那么我建议您子类UINavigationController
化并覆盖必要的属性/方法。如果你想改变导航栏的外观,你可以从你的 AppDelegate 中做到这一点,见这个。
推荐阅读
- python - 如何测量自上次调用函数以来经过的时间?
- reactjs - 使用 react-hook-form 对条件元素进行 Jest 单元测试
- javascript - 模态弹出窗口未在 JavaScript Ajax 拦截上传递 iFormFile 数据
- css - 谷歌自动完成下拉位置问题
- node.js - 如何在我的节点 js 天气应用程序中忽略错误的地名
- reactjs - 如何使用反应测试库模拟 ResizeObserver 以在单元测试中工作
- c# - 有没有办法检查 ac# 类是否是 json 可序列化和可反序列化的
- javascript - 试图打开特定选项卡的弹出窗口
- angular - Ionic ,使用 ion-select 并尝试将值从子级传递给父级不起作用
- deep-learning - 使用面部标志作为输入的好方法