0
  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.

bug man
  • 1
  • 1

2 Answers2

0

try this code in tab bar app

[self.tabBarController.navigationController popToRootViewControllerAnimated:YES];
kirti Chavda
  • 3,029
  • 2
  • 17
  • 29
  • sorry,i mean to stop the navigationController popToRootViewController when i double click the navigation's tabbarItem .thanks for answer – bug man Sep 24 '13 at 06:49
0

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];
}
karthika
  • 4,085
  • 3
  • 21
  • 23
  • 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;} – bug man Sep 24 '13 at 07:32