gpt4 book ai didi

ios - 呈现自定义选项卡 View Controller 但出现黑屏

转载 作者:行者123 更新时间:2023-11-29 11:47:55 27 4
gpt4 key购买 nike

我的目标是显示一个选项卡 View Controller ,该 Controller 管理多个选项卡,这些选项卡由包含 View Controller 的导航 Controller 组成。

我在 AppDelegate 中将选项卡 View Controller BaseTabBarController 设置为窗口我的 Root View Controller 。我的自定义选项卡 View Controller 如下所示:

class BaseTabBarController: ESTabBarController {

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .red

let v1 = BaseNavigationController(rootViewController: SubscriptionsController())
let v2 = BaseNavigationController(rootViewController: SubscriptionsController())

v1.tabBarItem = ESTabBarItem(title: "Home", image: #imageLiteral(resourceName: "tab_bar_home"), selectedImage: #imageLiteral(resourceName: "tab_bar_home"))
v2.tabBarItem = ESTabBarItem(title: "Home", image: #imageLiteral(resourceName: "tab_bar_home"), selectedImage: #imageLiteral(resourceName: "tab_bar_home"))

self.viewControllers = [v1, v2]
self.hidesBottomBarWhenPushed = true
}
}

我的自定义导航 Controller 类是导航 Controller 的空子类。

问题是应用程序显示标签栏几分之一秒,然后立即变成黑屏(控制台消息:“不鼓励在分离的 View Controller 上显示 View Controller ”)。我做错了什么?

最佳答案

您代码的其他部分一定有问题。当我使用你的代码并像这样使用它时,一切都按预期工作:

class BaseTabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .red

let v1 = UINavigationController(rootViewController: UIViewController())
let v2 = UINavigationController(rootViewController: UIViewController())

v1.tabBarItem = UITabBarItem(title: "Home", image: nil, selectedImage: nil)
v2.tabBarItem = UITabBarItem(title: "Home", image: nil, selectedImage: nil)

self.viewControllers = [v1, v2]
self.hidesBottomBarWhenPushed = true
}
}

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = BaseTabBarController()
window?.makeKeyAndVisible()

return true
}

关于ios - 呈现自定义选项卡 View Controller 但出现黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42588746/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com