当WKWebView尝试呈现WKActionSheet时,长按会导致错误/警告

Sha*_*oop 8 objective-c ios presentviewcontroller wkwebview

我的视图层次结构如下所示:

  • (root)PRSBaseViewController - 一个UIViewController子类 - 具有子viewControllers
    • (已提交)PRSModalWebViewController - 一个UINavigationController子类
      • (推,动画:不)PRSWebViewController - 一个UIViewController子类--WKWebView是一个子视图.

当我尝试长按WebView中的链接时,我收到错误:

Warning: Attempt to present <WKActionSheet: 0x127520d10> on <PRSBaseViewController: 0x1275117f0> whose view is not in the window hierarchy!

presentViewController:animated:completion不是使用addChildViewController:舞蹈来呈现导航,而是使用舞蹈将视图控制器添加到层次结构中.我没有错,这很奇怪.

有谁知道什么可能导致视图层次结构问题?

更新:我已经完成了所有课程要点

小智 13

我遇到过类似的行为 - 并且还没有弄清楚这是怎么发生的.

这是我的解决方法.由于WKWebView正在调用我的RootViewController,我通过覆盖RootViewController的presentViewController处理它:animated:completion: - 如果RootViewController已经有一个presentViewController,那么它将消息转发给该控制器.它似乎解决了警告信息,并在模态视图中使用WKWebView时给了我长按菜单.

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion {

    // Unsure why WKWebView calls this controller - instead of it's own parent controller
    if (self.presentedViewController) {
        [self.presentedViewController presentViewController:viewControllerToPresent animated:flag completion:completion];
    } else {
        [super presentViewController:viewControllerToPresent animated:flag completion:completion];
    }
}
Run Code Online (Sandbox Code Playgroud)

或者在快速:

override func presentViewController(viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)?) {
    if presentedViewController != nil {
        // Unsure why WKWebView calls this controller - instead of it's own parent controller
        presentedViewController?.presentViewController(viewControllerToPresent, animated: flag, completion: completion)
    } else {
        super.presentViewController(viewControllerToPresent, animated: flag, completion: completion)
    }
}
Run Code Online (Sandbox Code Playgroud)