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