0
votes
  1. first I Install TabBarController directly as a window’s root view controller,and hava a NavigationController in viewControllers.
  2. when the app run, I push some new viewcontroller onto the navigation stack
  3. than I tap navigation tabbaritem, the navigationController poptoRootViewController

How can I crash the step 3 event or stop it pop to root?

My solution to stop auto pop to root viewcontroller:

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
UITabBarController *tbc = [[UITabBarController alloc]init];

tbc.viewControllers = [NSArray arrayWithObjects:rvc,nil];

tbc.delegate = self;}
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{

if([tabBarController selectedViewController] == viewController)
    return NO;
return YES;}

if you have an anther solution,wellcome write down.

2

2 Answers

0
votes

try this code in tab bar app

[self.tabBarController.navigationController popToRootViewControllerAnimated:YES];
0
votes

You implement didSelectViewController method in new viewController(push to new viewController)

Import UITabBarControllerDelegate,

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.tabBarController.delegate = self;
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    [self.tabBarController.navigationController popToRootViewControllerAnimated:YES];
}