问题
Please help me find solution for case:
I have UITabBarController
in storyboard. When I tap on a TabBarItem (index 1), I should check variable (int)'ShowVC' to show corresponding view controller.
E.g:
switch (ShowVC) {
case 1:
showViewController1;
break;
case 2:
showViewController2;
break;
case 3:
showViewController3;
break;
default:
break;
}
So, what is solution for it?
Where can I add check method to show view controller when tapped TabBarItem?
回答1:
This link will definitely help.
http://www.mysamplecode.com/2013/02/ios-tab-bar-controller-example.html
回答2:
What I understand is you need to get Notification when your Tab is clicked or Tapped.
in AppDelegate's didFinishLaunchingWithOptions
UITabBarController *tabBar = (UITabBarController *)self.window.rootViewController;
[tabBar setDelegate:self];
Now in didSelectViewController
you can write your logic or condition about what to display.
- (void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
//Write your logic here
tabBarController.selectedViewController = yourNewController;
}
来源:https://stackoverflow.com/questions/36395972/ios-tapped-on-tabbaritem-check-variable-to-show-corresponding-viewcontroller