Prevent automatic popToRootViewController on double-tap of UITabBarController

前端 未结 5 1953
别跟我提以往
别跟我提以往 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 08:05

    Use the tabBarController:shouldSelectViewController: method of the UITabBarControllerDelegate protocol.

    - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
        return viewController != tabBarController.selectedViewController;
    }
    

    Don't forget to set the delegate of the tab bar controller to the object that actually implements this delegate method.

提交回复
热议问题