【发布时间】:2020-11-14 09:35:05
【问题描述】:
XCode MacOS(不是 iOS)使用 WKWebView 在窗口中打开 URL:
@property (assign) IBOutlet NSView *webNSView;
@property (assign) IBOutlet WKWebView *webView;
- (void)windowDidLoad {
WKWebView *webView = [[WKWebView alloc] initWithFrame:self.webNSView.frame];
webView.navigationDelegate = self;
NSURL *nsurl=[NSURL URLWithString:@"https://google.com"];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[webView loadRequest:nsrequest];
[self.webNSView addSubview:webView]; }
这工作正常。
我想使用 [self blankUrl] 发送一个空白网址;
我有这个:
-(void) blankUrl {
NSURL *nsurl=[NSURL URLWithString:@"about:blank"];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[webView loadRequest:nsrequest];
}
但我收到错误:“未知接收器 'webView';您的意思是 'WebView'?”
更改为 WebView 会出现错误:“无法识别的选择器已发送到类。”
更改为 self.webView 将编译但不加载 url。
基本上,如何更新 WKWebView URL?
【问题讨论】:
标签: objective-c xcode macos webview wkwebview