简体   繁体   English

从UIWebView切换到WKWebView时发生错误

[英]An error occurred when switching from UIWebView to WKWebView

I am developing an iOS application with Objective-C , I wanted to move from UIWebView to WKWebView . 我正在使用Objective-C开发iOS应用程序,我想从UIWebView转到WKWebView

However, an error occurred in the part which I wrote in this way before. 但是,我以前以这种方式编写的部分发生了错误。

    WKWebView * webview = [[WKWebView alloc] initWithFrame: CGRectZero];
    ...
    if (! webview.request) {
        ...
    }

The errors are as follows. 错误如下。

Property 'request' not found on object of type 'WKWebView *' 在“ WKWebView *”类型的对象上找不到属性“ request”

If you can understand, please tell me how to fix it. 如果您能理解,请告诉我如何解决。

Thank you. 谢谢。

Error message is clear WKWebView don't have request property you should use load(_ request: URLRequest) -> WKNavigation? 错误消息很清楚WKWebView没有request属性,您应该使用load(_ request: URLRequest) -> WKNavigation? method and check for url property instead 方法,然后检查url属性

as is defined in WKWebView class WKWebView类中所定义

/*! @abstract The active URL.
 @discussion This is the URL that should be reflected in the user
 interface.
 @link WKWebView @/link is key-value observing (KVO) compliant for this
 property.
 */
open var url: URL? { get }

your code should be 您的代码应该是

WKWebView * webview = [[WKWebView alloc] initWithFrame: CGRectZero];
...
if (!webview.url) {
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM