从子视图返回根视图,然后切换tabBar问题

先说一下我项目的架构: 由于设计的一个需求,我自定义了tabBar(就是写个view,view上放置按钮,按钮上放置icon和title,设置好选中和非选中状态,最后KVC方式替换掉系统的tabBar),然后tabBar对应4个导航控制器,导航控制器对应普通的VC。

后来遇到一个问题,在第三个tabBar的子视图中,有个按钮,需要切换到首页,结果点击按钮确实切换到了首页

[[NSNotificationCenter defaultCenter] postNotificationName:kCodeMethodChangeTabBarNotification object:@0];

但是当我点tabBar第三个item时,页面还是之前的界面,然后我在子视图的按钮事件中加了popToRootViewControllerAnimated

[self.navigationController popToRootViewControllerAnimated:NO];
[[NSNotificationCenter defaultCenter] postNotificationName:kCodeMethodChangeTabBarNotification object:@0];

结果点击按钮切换到首页时,底部tabBar消失了,开始我以为是我自定义tabBar产生的问题,我又注掉自定义tabBar,换成系统tabBar,结果问题依然存在,这时候意识到不是这个问题。

不写popToRoot,能返回且tabBar不消失,写了能返回但消失了。因为有多个地方有如此需求,无意间点到其中一个,既能返回且底部tabBar不消失,看了下代码,只是将两句代码位置变换了。

[[NSNotificationCenter defaultCenter] postNotificationName:kCodeMethodChangeTabBarNotification object:@3];
[self.navigationController popToRootViewControllerAnimated:NO];

不明白这是什么情况,大概搜索了下,看到这个文章,既然这样,暂时这样了

你可能感兴趣的:(从子视图返回根视图,然后切换tabBar问题)