UITabBarViewController

Description

UITabBarViewController is a connector which can easily enable the user to switch between different UIViewControllers. The ViewControllers are not connected with each other, and by default doing any actions in one of them does nothing in second one.

Basic Usage

To programatically create that kind of navigation, one has to create his own ViewController which will extend UITabBarController:

Example:

1
2
3
4
5
6
class RootViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

The code above creates empty ViewController. To add different tabs one has to create an instance of another UIViewController and UITabBarItem. UITabBarItem will be visible on the bottom of the screen and can have a title and image. To that Item one has to attach his own ViewController.

Example:

1
2
3
let tabTwo = UIViewController()
let tabTwoBarItem2 = UITabBarItem(title: "Stock", image: UIImage(named: "Move by Trolley_808080_25"), selectedImage: UIImage(named: "Move by Trolley_808080_25"))
tabTwo.tabBarItem = tabTwoBarItem2

It is possible to insert differnt NavigationController hierarchy to each tab. One has to be aware that each NavigationHierarchy is a sperate array which does not know about his sibligns.

Example:

1
2
3
4
let tabOneNavigationController = UINavigationController()
let tabOne = UITableViewController(style:UITableViewStyle.grouped)
tabOneNavigationController.viewControllers.append(tabOne)
let tabOneBarItem = UITabBarItem(title: "Order", image: UIImage(named: "Todo List_808080_100"), selectedImage: UIImage(named: "Todo List_808080_100"))

After creating the tabs and coresponding ViewControllers, developer has to assign them to parent UITabBarViewController.

Example:

1
self.viewControllers = [tabOneNavigationController, tabTwo]