ios - 如何更改 TabBar 项目导航标题

标签 ios swift uitabbarcontroller uitabbar

我遇到了一个问题!我已经挣扎了好几天了!我的问题是我无法更改 TabBar 项目中的导航标题。

首先,如果用户已经登录,我会从 App delegate 推送到 UITabBarViewController

let currentUser = PFUser.currentUser()
        if currentUser != nil {
            let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let HomeView : UIViewController = mainStoryboardIpad.instantiateViewControllerWithIdentifier("4")

            let navigationController = application.windows[0].rootViewController as! UINavigationController
            navigationController.pushViewController(HomeView, animated: false)
        } else {

        }

然后在第一项 ViewController 中,我使用它来更改 TitleView 图像等。

let logo = UIImage(named: "logo.png")
let imageView = UIImageView(image:logo)
self.navigationController!.topViewController!.navigationItem.titleView = imageView

在第二项 ViewController 中,我使用它再次更改标题。

self.navigationController!.topViewController!.navigationItem.titleView = nil
 self.navigationController!.topViewController!.navigationItem.title = "Second"

但是当我回到第一个项目时,我应该看到我设置的图像,而不是第二个项目 View Controller 的标题

最佳答案

替换

self.navigationController!.topViewController!.title = "Mes contacts"

self.navigationController!.topViewController!.navigationItem.title = "Mes contacts"

关于ios - 如何更改 TabBar 项目导航标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35225898/

相关文章:

iOS)如何制作顶部和底部固定 View 的Tab View

ios - 如何将选项卡栏 Controller 添加到 iOS 中的 subview ?

ios - 两个 Storyboard,都包含 TabBarControllers。如何在他们之间进行segue?

ios - 使用适用于 ios 的 google map sdk 检查 google 街景的可用性

ios - 如何将 NSIndexPath 转换为 NSString-iOS

ios - 当 View Controller 不是选定的选项卡或未显示时 NSTimer 停止

swift - RealityKit – 获取 ModelEntity 大小作为 SIMD3<Float>

ios - SwiftUI 中 ScrollView 底部对齐中的 VStack

ios - [NSNull 长度] : unrecognized selector sent to instance in objective-c

json - 如何设置下载数据的时间限制(来自 json 数据库)Swift 2