IOS - Tapped on TabBarItem, check variable to show corresponding ViewController

十年热恋 提交于 2019-12-11 01:04:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!