在appdelegate中添加UITabbarController

时间:2019-04-10 06:15:55

标签: swift uitabbarcontroller

我想将Tabbar添加到应用程序。但是我不知道如何在AppDelegate上执行此操作。我希望在打开maintableviewcontroller时将代码添加到标签栏中。但是我不希望在maintableviewcontroller打开之前添加选项卡。当我添加Tabbar时,在打开应用程序时maintableviewcontroller总是打开。例如,当我退出应用程序时,不应打开带有maintainleviewcontroller的实现。那么如何将tabbari添加到maintableviewcontrols中?

class AppDelegate: UIResponder, UIApplicationDelegate, UITabBarControllerDelegate {
var window: UIWindow?
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
         FirebaseApp.configure()

         let tabBarController = ESTabBarController()
        tabBarController.delegate = self
        tabBarController.tabBar.shadowImage = UIImage(named: "transparent")
        tabBarController.tabBar.backgroundImage = UIImage(named: "background_dark")

        let v1 = MainTableViewController()
        let v2 = NewMainTableViewController()
        let v3 = MainTableViewController()
        let v4 = ContactViewController()

        DispatchQueue.main.asyncAfter(deadline: .now() + 2 ) {
            v2.tabBarItem.badgeValue = "1"
        }

        v1.tabBarItem = ESTabBarItem.init(ExampleBouncesContentView(), title: "Anasayfa", image: UIImage(named: "homepage"), selectedImage: UIImage(named: "socket-4"))
        v2.tabBarItem = ESTabBarItem.init(ExampleBouncesContentView(), title: "Yeni Cihaz", image: UIImage(named: "socketmenu"), selectedImage: UIImage(named: "energy"))
        v3.tabBarItem = ESTabBarItem.init(ExampleBouncesContentView(), title: nil, image: UIImage(named: "homepage"), selectedImage: UIImage(named: "homepage"))
        v4.tabBarItem = ESTabBarItem.init(ExampleBouncesContentView(), title: "İletişim", image: UIImage(named: "homepage"), selectedImage: UIImage(named: "contactmenu-1"))


        tabBarController.viewControllers = [v1, v2, v3, v4]

        tabBarController.navigationController?.navigationBar.backgroundColor = UIColor.flatSand
        tabBarController.navigationController?.navigationBar.isTranslucent = true

        window = UIWindow(frame: UIScreen.main.bounds)
        let navigationControllerNew = ExampleNavigationController.init(rootViewController: tabBarController)


    let navigationController = UINavigationController(rootViewController: MainTableViewController())
     // window?.rootViewController = navigationControllerNew

        window?.rootViewController = navigationController

        window?.makeKeyAndVisible()
        return true
    }
}

0 个答案:

没有答案
相关问题