我正在尝试为我的 iOS 应用程序实现底部导航栏。但是,当我创建 tabBarItem 时,它没有显示在 TabBar 上。TabBar 显示正确。我无法弄清楚问题出在哪里,任何帮助将不胜感激。
如果需要任何其他信息,请给我一个标志。我的代码(简化):
应用委托:
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = TabBarController()
return true
}
}
Run Code Online (Sandbox Code Playgroud)
标签栏控制器:
class TabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
let homeController = HomeController()
let navigationController = UINavigationController(rootViewController: homeController)
navigationController.title = "Home"
navigationController.tabBarItem.image = UIImage(named: "icon")
viewControllers = [homeController]
}
}
Run Code Online (Sandbox Code Playgroud)
家庭控制器:
class HomeController: UIViewController …Run Code Online (Sandbox Code Playgroud)