UINavigationController出现nested push animation can result in corrupted navigation bar的错误提示

时间:2021-07-20 15:50:56

今天在測试过程中,出现了这样一个bug。分别有两种情景:

(前提是:app是基于UINavigationController构建的)

1、从Controller-A中push进来B。在B中点击返回,返回的界面为黑色一片。再做返回操作就crash了。

如图1:

UINavigationController出现nested push animation can result in corrupted navigation bar的错误提示

2、从Controller-A中push进入B,此时B中tableview出现错位现象(图2)。tableview被navigationbar覆盖了一部分,在B中再push一个C进来。

此时仅仅显示了C的navigationbar,但下方的view还是保留为B的view(图3)。

再进行返回操作,程序crash。

如图2:

UINavigationController出现nested push animation can result in corrupted navigation bar的错误提示

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc2luZ19zaW5n/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

图3:

UINavigationController出现nested push animation can result in corrupted navigation bar的错误提示

崩溃后。查看控制台的log,发现这样一句话:

nested push animation can result in corrupted navigation bar





捣弄了好久,也找了资料,还是没办法解决。

后来在Controller-B中的viewdidload打印了navigationcontroller的全部压栈viewcontrollers,发如今B之前多了一个无关的viewcontroller-D,再检查代码。原来在点击A的cell的时候(didSelectRowAtIndexPath)push了一个D,但在storyboard上,对A的点击已经加了一个跳转到B的segue。正是因为同一时间push了两个controller进来,所以就会出现这种警告以及后面的奇怪错误。

将A中didSelectRowAtIndexPath位置的push代码去掉。再測试。问题全然攻克了。





纠缠了半天的bug,原来是一个小失误导致的。

因为整个项目是两个人一起做的,相互没沟通好或者没细致了解好结构就盲目写代码。终于仅仅会花费大量时间在debug上。此次教训须谨记啊。