问题描述
请帮助我找到解决方案:
我在情节提要中有 UITabBarController
.当我点击TabBarItem(索引1)时,我应该检查变量(int)'ShowVC'以显示相应的视图控制器.例如:
开关(ShowVC){情况1:showViewController1;休息;情况2:showViewController2;休息;情况3:showViewController3;休息;默认:休息;}
那么,什么是解决方案?
点击TabBarItem时,我可以在哪里添加检查方法以显示视图控制器?
我了解的是,单击或轻按Tab时需要获取通知.
在AppDelegate的 didFinishLaunchingWithOptions
中 UITabBarController * tabBar =(UITabBarController *)self.window.rootViewController;[tabBar setDelegate:self];
现在,在 didSelectViewController
中,您可以编写关于显示内容的逻辑或条件.
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{//在这里写你的逻辑tabBarController.selectedViewController = yourNewController;}
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?
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;
}
这篇关于iOS-点击TabBarItem,检查变量以显示相应的ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!