'How to check which Tab Bar item is active?

I am trying to figure out how to check which tab bar button is active? Currently I have 5 to 6 different tab bar buttons, and want to check which one is active. Any input will be appreciated here.

Thanks,

Shawn



Solution 1:[1]

do you have UITabbar or UITabbarController?

if UITabbar then set tag for each item and then you see which item is selected using -

tabBarController.tabBar.selectedItem.tag

if UITabbarController then use

tabBarController.selectedIndex

Solution 2:[2]

UITabBarController has a selectedViewController and a selectedIndex property. Here is the UITabBarController documentation

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Witek Bobrowski
Solution 2 Christian