我有一个控制器,我想以编程方式实例化WKWebView。 出于这个原因,我按故事板和代码添加了一个容器视图,我想在其中添加一个WKWebView。 这是代码:
#import "testController.h"
#import <WebKit/WebKit.h>
@interface testController()
@property (strong, nonatomic) WKWebView *webView;
@property (strong, nonatomic) IBOutlet UIView *container;
@end
@implementation testController
- (void)viewDidLoad
{
[super viewDidLoad];
self.webView = [[WKWebView new] initWithFrame:self.container.frame];
self.webView.scrollView.showsVerticalScrollIndicator = NO;
self.webView.scrollView.showsHorizontalScrollIndicator = NO;
self.webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.webView.frame = CGRectMake(0, 0, self.container.frame.size.width, self.container.frame.size.height);
[self.container addSubview:self.webView];
[self.webView loadHTMLString:@"testString "baseURL:nil];
}
@end
此代码有效,但并非总是如此,有时会崩溃,我在终端日志中收到此错误:
-[__NSCFString _webView:renderingProgressDidChange:]: unrecognized selector sent to instance 0x604000838ce0
2018-05-25 16:04:26.001917+0200 AppTest iOS[4853:171971] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString _webView:renderingProgressDidChange:]: unrecognized selector sent to instance 0x604000838ce0'
*** First throw call stack:
但我无法理解原因。
编辑1: 这个控制器在导航控制器内部,我注意到如果我放入导航控制器,我会收到此错误(有时),而我从导航控制器中删除它一切正常