iOS tabbarVC下pop和dismiss的区别

在项目解bug过程中,偶然发现自己的知识盲区。

一个跟控制器tabbarVC下面包含两个tab,在其中一个tab中一直push到第三层。例如,从首页-->商品页-->商品详情页。此时如果pop回来的话,只会走三个nav的viewWillAppear方法,与tabbarVC没有关系。

        NSMutableArray *array = [NSMutableArray array];
        LocalViewController *localVC = [[LocalViewController alloc] init];
        localVC.view.backgroundColor = [UIColor whiteColor];
        localVC.tabBarItem.title = @"本地";
        localVC.tabBarItem.image = [[UIImage imageNamed:@"tab_mall_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        localVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"tab_mall_select"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        UINavigationController *localNav = [[UINavigationController alloc] initWithRootViewController:localVC];
        [array addObject:localNav];
        
        MineViewController *mineVC = [[MineViewController alloc] init];
        mineVC.view.backgroundColor = [UIColor whiteColor];
        mineVC.tabBarItem.title = @"我的";
        mineVC.tabBarItem.image = [[UIImage imageNamed:@"tab_mine_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        mineVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"tab_mine_select"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        UINavigationController *mineNav = [[UINavigationController alloc] initWithRootViewController:mineVC];
        [array addObject:mineNav];
        self.selectedIndex = 0;
        self.viewControllers = array;

此时若从商品页present到商品详情页,从商品详情页dismiss回商品页,会依次调用tabbarVC的viewWillAppear--->商品页VC的viewWillAppear--->tabbarVC的viewDidAppear--->商品页VC的viewDidAppear。(原以为不会走tabbar方法,经过调试才知道自己想当然了。)

你可能感兴趣的:(iOS tabbarVC下pop和dismiss的区别)