Switching to a TabBar tab view programmatically?

后端 未结 12 1944
南旧
南旧 2020-11-29 17:07

Let\'s say I have a UIButton in one tab view in my iPhone app, and I want to have it open a different tab in the tab bar of the TabBarController.

12条回答
  •  鱼传尺愫
    2020-11-29 17:46

    Use in AppDelegate.m file:

    (void)tabBarController:(UITabBarController *)tabBarController
     didSelectViewController:(UIViewController *)viewController
    {
    
         NSLog(@"Selected index: %d", tabBarController.selectedIndex);
    
        if (viewController == tabBarController.moreNavigationController)
        {
            tabBarController.moreNavigationController.delegate = self;
        }
    
        NSUInteger selectedIndex = tabBarController.selectedIndex;
    
        switch (selectedIndex) {
    
            case 0:
                NSLog(@"click me %u",self.tabBarController.selectedIndex);
                break;
            case 1:
                NSLog(@"click me again!! %u",self.tabBarController.selectedIndex);
                break;
    
            default:
                break;
    
        }
    
    }
    

提交回复
热议问题