0

I want to add Tabbar to my application. Tabbar is not visible even though I have already added the codes. How do I add AppDelegate if I can't add it from UITableViewController? What had I better do?

class MainTableViewController: UITableViewController {

     private func tabbar() {
            let tabBarController = FluidTabBarController()
            tabBarController.tabBar.tintColor = UIColor(red: 0.2431372549, green: 0.4235294118, blue: 1, alpha: 1)
            let viewControllers = [
                ("News", #imageLiteral(resourceName: "output-onlinepngtools")),

                ].map(createSampleViewController)
            tabBarController.setViewControllers(viewControllers, animated: true)

        }

        private func createSampleViewController(title: String, icon: UIImage) -> UIViewController {
            let viewController = UIViewController()
            viewController.view.backgroundColor = #colorLiteral(red: 0.9490196078, green: 0.9529411765, blue: 0.968627451, alpha: 1)
            let item = FluidTabBarItem(title: title, image: icon, tag: 0)
            item.imageColor = #colorLiteral(red: 0.7960784314, green: 0.8078431373, blue: 0.8588235294, alpha: 1)
            viewController.tabBarItem = item
            return viewController
        }

    override func viewDidLoad() {
            super.viewDidLoad()
            tabbar()
    }
 }
B K.
  • 534
  • 5
  • 18
stakabekor
  • 453
  • 1
  • 6
  • 11

1 Answers1

0

I think that's what you asked for, just embed your ViewController in the UITabBarController

storyboard

If you want to do this programatically you need to create your UITabBarController and add your custom view controllers. in your case the FirstViewController is gonna be a UITableViewController

class MyUITabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let firstViewController = FirstViewController()

        firstViewController.tabBarItem = UITabBarItem(tabBarSystemItem: .search, tag: 0)

        let secondViewController = SecondViewController()

        secondViewController.tabBarItem = UITabBarItem(tabBarSystemItem: .more, tag: 1)

        let tabBarList = [firstViewController, secondViewController]

        viewControllers = tabBarList
    }
}

Then instantiate your UITabBarController in didFinishLaunchingWithOptions

window?.rootViewController = MyUITabBarController()
window?.makeKeyAndVisible()

and the job is done!

Alastar
  • 1,284
  • 1
  • 8
  • 14