简体   繁体   English

黑屏标签栏 Controller

[英]Black Screen Tab Bar Controller

I am facing a problem.我面临一个问题。 When I want to change the View for a Tab View Controller, my application gives a black screen.当我想更改选项卡视图 Controller 的视图时,我的应用程序出现黑屏。

在此处输入图像描述

And here is my code to change view:这是我更改视图的代码:

let homeViewController = self.storyboard?.instantiateViewController(identifier: Constants.Storyboard.homeViewController) as? HomeViewController

self.view.window?.rootViewController = homeViewController
self.view.window?.makeKeyAndVisible()

Constants.swift:常量.swift:

import Foundation

struct Constants {

    struct Storyboard {

        static let homeViewController = "homeVC"

    }
}

homeVC is the first View of TabBarController, with the Label. homeVC 是 TabBarController 的第一个 View,带有 Label。

This is my way.这是我的方式。 I am not using storyboard by the way.顺便说一句,我没有使用 storyboard。 I am using xib.我正在使用xib。

let dashboardVc = DashboardTabController()
self.window!.rootViewController = dashboardVc
self.window!.makeKeyAndVisible()
self.window?.overrideUserInterfaceStyle = .light

and then in dashboardTabController type this one.然后在dashboardTabController 中输入这个。

import UIKit

class DashboardTabController: UITabBarController {

    @IBOutlet weak var dashboardTabBar: UITabBar!

    override func viewDidLoad() {
        super.viewDidLoad()

        let firstViewController = HomeViewController()

        firstViewController.tabBarItem = UITabBarItem(title: "", image: UIImage(named: "ic_home_24px"), selectedImage: UIImage(named: "ic_home_24px"))

        let secondViewController = AddContactViewController()

        secondViewController.tabBarItem = UITabBarItem(title: "", image: UIImage(named: "ic_group_add_24px"), selectedImage: UIImage(named: "ic_group_add_24px"))

        let tabBarList = [firstViewController, secondViewController]

        viewControllers = tabBarList
    }
}

don't forget in DashBoardTabController xib, implement the UITabBar in bottom.不要忘记在 DashBoardTabController xib 中,在底部实现 UITabBar。 Hopefully it's helpful.希望它会有所帮助。 Just mention me if you need more help on executing this.如果您在执行此操作时需要更多帮助,请提及我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM