Attempt to present <UIImagePi

2018-10-25  本文已影响294人  iOS小乔

问题描述

当从一个controller present 到 webviewcontroller,加载的html弹框选取照片时,选取之后并没有弹出imagepickcontroller,而且当前的webviewcontroller也会dismiss掉,并且控制台输出错误内容

Warning: Attempt to present <UIImagePickerController: 0x7fe7fc008600> on <Test.XYNavigationViewController: 0x7fe7fc860a00> whose view is not in the window hierarchy!

Simulator Screen Shot - iPhone X - 2018-10-25 at 17.06.31.png

在我们重写了dismiss方法

override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
    print("test")
    super.dismiss(animated: flag, completion: completion)
}

会发现test输出了两次


Snip20181025_1.png

UIWebview使UIAlertcontrollerUIWebviewviewcontroller上显示以显示相机/现有/取消。当用户选择选项时,UIAlertcontroller意味着被释放并且UIImagepickercontroller被呈现。然而,对UIAlertcontroller的释放似乎调用了两次。第一次是好的,因为presentviewcontroller =UIAlertcontroller,但第二次presentviewcontroller属性为nil,这导致dismissviewcontroller animated方法杀死UIWebviewviewcontroller

解决方法:

在自定义的UINavigationcontroller做些操作

class XYNavigationViewController: UINavigationController {

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
    self.view.window?.rootViewController = self
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destination.
    // Pass the selected object to the new view controller.
}
*/

override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
    print("test")
    if let vc = self.presentedViewController {
        // don't bother dismissing if the view controller being presented is a doc/image picker
        if !vc.isKind(of: UIDocumentMenuViewController.self) || !vc.isKind(of:UIImagePickerController.self) {
            super.dismiss(animated: flag, completion:completion)
        }
    }

}

}

参考链接地址:https://stackoverflow.com/questions/25942676/ios-8-sdk-modal-uiwebview-and-camera-image-picker

上一篇下一篇

猜你喜欢

热点阅读