moreNavigationController在UITabBarController中始终为nil

时间:2017-08-18 06:01:30

标签: ios swift uitabbarcontroller

我尝试在UITabBarController中自定义“更多”按钮的标题,因为我正在使用其他语言进行应用。我将UITabBarController子类化,以便能够访问tabBarController属性。不幸的是,它总是nil我把它放在viewDidLoadviewDidAppear(_)中。关于如何编辑它的任何想法?

import UIKit

class ControllerVC: UITabBarController {

let uiManager = UIManager()

override func viewDidLoad() {
    super.viewDidLoad()
}

override func viewDidAppear(_ animated: Bool) {
    if let tabBarItem = tabBarController?.moreNavigationController.tabBarItem {
        let deselectedImage = tabBarItem.image
        let selectedImage = tabBarItem.selectedImage
        tabBarController!.moreNavigationController.tabBarItem = UITabBarItem(title: "بیشتر", image: deselectedImage, selectedImage: selectedImage)
    } else {
        uiManager.showActivityIndicator(self)
    }
}

}

1 个答案:

答案 0 :(得分:2)

问题不在于moreNavigationController。问题出在tabBarController上。你的班级是UITabBarController。标签栏控件的tabBarController属性始终为nil

只是做:

let tabBarItem = moreNavigationController.tabBarItem
let deselectedImage = tabBarItem.image
let selectedImage = tabBarItem.selectedImage
moreNavigationController.tabBarItem = UITabBarItem(title: "بیشتر", image: deselectedImage, selectedImage: selectedImage)