Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/122.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript -[UIAlertController addTextFieldWithConfigurationHandler:]中的断言失败_Javascript_Ios_Swift_Wkwebview_Wkuidelegate - Fatal编程技术网

Javascript -[UIAlertController addTextFieldWithConfigurationHandler:]中的断言失败

Javascript -[UIAlertController addTextFieldWithConfigurationHandler:]中的断言失败,javascript,ios,swift,wkwebview,wkuidelegate,Javascript,Ios,Swift,Wkwebview,Wkuidelegate,在WKWebView内的JavaScript中调用窗口。提示符,会生成断言错误: -[UIAlertController]中的断言失败 addTextFieldWithConfigurationHandler:] 断言错误来自此WKUIDelegate函数: func webView(_ webView: WKWebView, runJavaScriptTextInputPanelWithPrompt prompt: String, defaultText: String?, initiated

在WKWebView内的JavaScript中调用
窗口。提示符
,会生成断言错误:

-[UIAlertController]中的断言失败 addTextFieldWithConfigurationHandler:]

断言错误来自此WKUIDelegate函数:

func webView(_ webView: WKWebView, runJavaScriptTextInputPanelWithPrompt prompt: String, defaultText: String?, initiatedByFrame frame: WKFrameInfo,
             completionHandler: @escaping (String?) -> Void) {

    let alertController = UIAlertController(title: nil, message: prompt, preferredStyle: .actionSheet)

    alertController.addTextField { (textField) in
        textField.text = defaultText
    }

    alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action) in
        if let text = alertController.textFields?.first?.text {
            completionHandler(text)
        } else {
            completionHandler(defaultText)
        }
    }))

    alertController.addAction(UIAlertAction(title: "Cancel", style: .default, handler: { (action) in
        completionHandler(nil)
    }))

    present(alertController, animated: true, completion: nil)
}

类文档没有显示在添加文本字段或初始值设定项时添加配置处理程序的方法。那么您应该如何处理这个问题呢?

尝试将样式
操作表更改为
警报
。对于将从
UIAlertControllerStyleActionSheet
更改为
UIAlertControllerStyleAlert
的Objective-C用户,应从viewController调用Present。怀疑您可能就是这种情况。

在调用
present
之前,在配置警报控制器时似乎发生了断言。您能否举出一个在尝试呈现警报时发生此断言失败的示例?