1

I am using Tab Bar i.e. Bottom bar and have 5 tab bar items, i want to assign a method to each, so that i can navigate to other views on tab bar item click.

I've been looking for some clues, but couldn't make it.

Ozgur Vatansever
  • 49,246
  • 17
  • 84
  • 119
Shikha Sharma
  • 451
  • 1
  • 5
  • 25

2 Answers2

4

Use UITabBarDelegate.

Implement your class and inherit the protocol by adding after your class definition

@interface MyViewController : UIViewController<UITabBarDelegate>

and then use method tabBar:didSelectItem: in that class

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    // Do Stuff!
    // if(item.title == @"First") {...}
}

May be it will help you

1

In Swift

Implement UITabBarDelegate and use method didSelect

class MyViewController: UIViewController, UITabBarDelegate {
    func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
    }
}

Also create IBOutlet to toolbar

toolbar.delegate = self

Abdulmoiz Ahmer
  • 1,953
  • 17
  • 39