单击导航tabbaritem popToRootViewController

时间:2013-09-24 06:32:25

标签: ios objective-c

  1. 首先我将TabBarController直接安装为窗口的根视图控制器,并在viewControllers中使用NavigationController。
  2. 当app运行时,我将一些新的viewcontroller推送到导航堆栈
  3. 比我点击导航tabbaritem,navigationController poptoRootViewController
  4. 如何使第3步事件崩溃或将其停止为root?

    我的解决方案是停止自动弹出到根视图控制器:

    -(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;}
    

    如果您有另一个解决方案,请记下好处。

2 个答案:

答案 0 :(得分:0)

在标签栏应用中尝试此代码

[self.tabBarController.navigationController popToRootViewControllerAnimated:YES];

答案 1 :(得分:0)

您在新的viewController中实现了didSelectViewController方法(推送到新的viewController)

导入UITabBarControllerDelegate,

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