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.
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.
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
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