简体   繁体   中英

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.

在此处输入图像描述

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:

import Foundation

struct Constants {

    struct Storyboard {

        static let homeViewController = "homeVC"

    }
}

homeVC is the first View of TabBarController, with the Label.

This is my way. I am not using storyboard by the way. I am using xib.

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

and then in dashboardTabController type this one.

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. Hopefully it's helpful. Just mention me if you need more help on executing this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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