iOS 7中使用UINavigationController进行pop的坑

      最近发现了在iOS7中使用UINavigationController的一个坑,看见stackOverFlow中,也有人在问,刚好也解决了问题,今天就在这儿共享下解决方案吧!

      先来看看问题吧,代码如下:(来自stackOverFlow)

I am using following line of code:

[self.navigationController popViewControllerAnimated:YES];

But it is not behaving in ios 7 as it doing in ios 6.Some times it does not pop controller while we are pressing back button 2- 3 times in succession.

Resulting in abrupt behaviour in navigation bar and deallocating a controller but showing the same on ui .

So when we press anything on that controller it results to a crash since controller is already deallocated.

大体意思就是,在iOS 7 中使用popViewControllerAnimated,这个方法,并不像在iOS 6中那么好使(在iOS8 以上也挺好使),就造成了不能正常pop出来的问题,具体愿意,我觉得下边这个人回答的挺好:

I'm happy that I am not the only one this has happened to. iOS 7+ bug (just got it in iOS 8, too). The view is popped from the navigation stack, but not animated from the UI. Then it gets stuck there, since it's no longer a part of the stack!

大体意思:其实改pop出来的页面其实已经从navigation stack中pop出去了,但是UI的动画却没有机结束,然后你又从已经不在navigation stack中的view,继续动画,然后你就会发现卡在那里了,继而程序崩溃!

 既然已经找到了问题,那么我开始的思路是,让不要动画,也就是:

[self.navigationController popViewControllerAnimated:NO];

然并卵~

之后想到,既然他的原因是view已经pop出去了,才进行UI的animate,那么我们何不延迟几秒钟,等他view的pop动作结束,然后再进行UI的动画

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

[self.navigationController popViewControllerAnimated:YES];

});

这样就解决了问题!

大家在适配iOS 7的时候,可以借鉴下!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Swift版本点击这里欢迎加入QQ群交流: 594119878最新更新日期:18-09-17 About A cu...
    ylgwhyh阅读 25,586评论 7 249
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,259评论 4 61
  • 半夜五点,被电话吵醒,(因为港大只能留一个人陪同,所以就留了护理师在那)周总在电话那端说:宝宝不吃奶,护士和...
    你的晚安阅读 294评论 0 2
  • #241 · 匿名 | 表白 1天前 前女友对男生到底是一个怎样的存在,如果你的男朋友和前女友相敬如宾,和你打打闹...
    山工院表白墙阅读 140评论 0 0
  • 2017.09.24天气晴 今天和孩子一起阅读什么是多媒体,看着孩子拿这书在哪里读的真带劲,读顺了,我们...
    郝鸿涛妈妈阅读 179评论 0 0