Prevent automatic popToRootViewController on double-tap of UITabBarController

前端 未结 5 1954
别跟我提以往
别跟我提以往 2020-11-30 07:18

The default behavior of a UITabBarController is to pop the contained UINavigationController to the root view controller when a particular tab is tapped a second time. I have

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 07:44

    This behavior is a little strange, but a handy shortcut in case of deep hierarchy!

    You can implement following UITabBarControllerDelegate methods to disable this system wide shortcut:

    #pragma mark -
    #pragma mark UITabBarControllerDelegate
    
    - (BOOL)tabBarController:(UITabBarController *)tbc shouldSelectViewController:(UIViewController *)vc {
        UIViewController *tbSelectedController = tbc.selectedViewController;
    
        if ([tbSelectedController isEqual:vc]) {
            return NO;
        }
    
        return YES;
    }
    

提交回复
热议问题