导航栏按钮不可见 Swift

问题描述 投票:0回答:1

这是我修改后的 AppDelegate 函数

 var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    let button = UIBarButtonItem(title: "Logs", style: .plain, target: self, action: #selector(logButtonTapped))
    window?.rootViewController?.navigationItem.rightBarButtonItem = button
    return true
}

我还在我的 VC 之前添加了导航控制器,如下

即使标题可见,右侧导航按钮也不可见。如何使导航按钮可见以便我可以单击它?

另外,我在控制台上收到此错误

UINavigationBar 解码为 UINavigationController 未锁定,或 navigationBar 委托设置不正确。配置不一致可能会导致问题。

swift uinavigationbar appdelegate
1个回答
0
投票

我不确定我是否很好地理解了您的期望。但我认为您需要在应用程序的第一页上看到导航栏按钮。不是吗?

因此,您可以在

viewDidLoad()
方法中将其直接添加到 viewController 中,而不是在 AppDelegate 或 SceneDelegate 中执行此操作。

它会是这样的:

override func viewDidLoad() {
    super.viewDidLoad()
    let button = UIBarButtonItem(title: "Logs", style: .plain, target: self, action: #selector(self.logButtonTapped))
    navigationItem.rightBarButtonItem = button
}

如果这不是您所需要的,请提供更多相关信息

© www.soinside.com 2019 - 2024. All rights reserved.