I'm working on a radio streaming app with 2 UITabBarController buttons at the bottom of the app. One for Live Streaming and 开发者_开发技巧one for Top 40 list.
I'm using a common StreamingViewController for both the tabs. But depending on the tab selected - a different url needs to be passed to the StreamingViewController so that it can play the appropriate feed.
So how can i determine the active tab ?
Did you even look at the documentation? tabBarController.selectedIndex
will give you the index of the selected tab, and tabBarController.selectedViewController
will give you a pointer to the view controller at the active tab.
I'm not sure from where you are calling the code to load the URL, but you probably need to be notified when the user selects a different tab. Override your UITabBarController class, and implement didSelectViewController method:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
In this method, you should be able to pass the appropriate URL to your controller.
(I know this answer is kind of late, but I hope it helps)
So I stumbled upon this question as my app required the same functionality. The answer is : You can find active tab by tabBarController.tabBar.selectedItem.title this will give you title of active tab or you can use tabBarController.tabBar.selectedItem.tag if you have assigned tags to your tabBar Items. Hope it helps others from pulling their hair :P
精彩评论