iOS UIWebView打开相册的问题

这个问题在很早的时候遇到过一次,当时的解决办法通过push 而不是 modal 的方法。 但是这次又遇到了,而且不能用push的方法来解决了。so 能怎么办???

上链接:iOS 8 SDK: modal UIWebView and camera/image picker

对于这个问题出现的原因。里面有一段描述,原文是这样的。
The uiwebview causes the uialertcontroller to be presented on the uiwebviewviewcontroller to show the camera/existing/cancel. When user chooses option, then uialertcontroller is meant to be dismissed and the uuiimagepickercontroller presented. However the dismissing of the uialertcontroller seems to fire twice. The first time is ok because the presentedviewcontroller = the uialertcontroller , but the 2nd time the presentedviewcontroller property is nil, and this causes the dismissviewcontrolleranimated method to kill the webviewviewcontroller which is the problem, to I now test for this case。

大概意思就是:点击了 UIWebView 中打开相机的标签的时候,弹出了 UIAlertController, UIAlertController是通过modal到 UIWebView,当你点击了选项卡里面的选项的时候, UIAlertController 的dismissing执行了两次,第一次dismiss的是UIAlertController,但是第二次dismiss的是UIWebViewVC。

这样一来就知道了问题的原因,原来是点击UIWebView中弹出选择相机的选项卡的时候,当我选中了从相机打开后,这个对话框dismiss了两次,所以就导致了UIWebView所在的控制器也消失了。如果这个UIWebView所在的控制器是跟控制器的话,就会引起崩溃。

下面是解决办法。
你可以在你自定义的UINavigationController中添加以下代码,或者在UINavigationController的分类中添加一下代码。重写dismiss的代码

-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
{
if (self.presentedViewController)
{
[super dismissViewControllerAnimated:flag completion:completion];
}
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,496评论 0 23
  • 通常情况下我都不知道自己要什么,但是最近,就很想要一个拥吻。一个安安静静的拥吻。从正面抱紧吻我头发站着,从背后抱紧...
    VVVV阅读 2,985评论 1 1
  • 清晨起床,清醒的很利索,但真的很冷,还是在被窝里赖了一会儿。 天气虽然很冷,骑自行车的时候还是懒得从背包里面拿出新...
    二石兄阅读 1,346评论 0 2

友情链接更多精彩内容