当用户点击下拉列表HTML选择标记时,ios8 iPad uiwebview在显示弹出窗口时崩溃

see*_*ble 42 objective-c uiwebview ios8

在ios8和iPad上,如果a uiwebview显示包含下拉列表的HTML页面

例如,这个页面http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select

然后

  • 反复点击包含汽车列表的HTML下拉列表.第一项是沃尔沃.
  • 每隔1/2秒左右点击一下uipopover打开和关闭
  • 应用程序将崩溃:

由于未捕获的异常'NSGenericException'而终止应用程序,原因是:'UIPopoverPresentationController()应该在演示发生之前设置一个非零的sourceView或barButtonItem.

无论如何uiwebview在ios8中解决这个问题?

它不会发生使用wkwebview,但我想修复它uiwebview.

更新:这似乎有助于但不确定副作用.我在包含uiwebview的视图控制器中覆盖了以下内容.

-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
{
    if (completion)
    {
        completion();
    }

    [super dismissViewControllerAnimated:NO completion:nil];
}
Run Code Online (Sandbox Code Playgroud)

dog*_*god 42

问题中提到的解决方案对我没有帮助,但它确实指出了我正确的方向.经过一番调查后,我会说在呈现和移除弹出窗口之间存在某种竞争条件.作为一种解决方法,您可以将演示文稿推迟到UIWebView的委托中:

-(void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_USEC), dispatch_get_main_queue(),
               ^{
                   [super presentViewController:viewControllerToPresent animated:flag completion:completion];
               });
}
Run Code Online (Sandbox Code Playgroud)

  • 此修复程序在所有情况下都不起作用.如果用户使用键盘顶部的"前进"或"后退"按钮快速遍历表单字段,则应用程序仍会崩溃. (6认同)
  • 这应该在显示UIWebView的控制器上,而不是UIWebView的委托.通常这些对象是同一个对象,但它们不必是同一个对象. (5认同)

tan*_*one 9

以前的解决方案对我没有帮助.

Apple已经记录了一个错误(请参阅openradar).

问题似乎是Web视图尝试在弹出框中呈现视图控制器而不设置弹出窗口的sourceView.虽然这绝对是一个Apple问题,但我使用了以下解决方法来避免我的应用程序崩溃:

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
{
    // Override this method in the view controller that owns the web view - the web view will try to present on this view controller ;)

    if (viewControllerToPresent.popoverPresentationController && !viewControllerToPresent.popoverPresentationController.sourceView) {
        return;
    }

    [super presentViewController:viewControllerToPresent animated:flag completion:completion];
}
Run Code Online (Sandbox Code Playgroud)