OStack程序员社区-中国程序员成长平台

标题: ios - 大约 10 秒后开始加载 wkwebview 白页 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:40
标题: ios - 大约 10 秒后开始加载 wkwebview 白页

我想加载一个远程 url 页面,但它总是在大约 10 秒后开始加载 代码如下

- (UIWebView *)webView {
    if(!_webView) {
        _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        _webView.scalesPageToFit = YES;
        _webView.dataDetectorTypes = UIDataDetectorTypeAll;
        _webView.delegate = self;
    }
   return _webView;
}

- (void)viewDidLoad {
   [super viewDidLoad];
   // Do any additional setup after loading the view.
   [self editNavigationBar];
   NSLog(@"viewLodLoad");
   self.view.backgroundColor = [UIColor whiteColor];
   [self loadHTML:self.pageModel.url title:self.pageModel.postUser];
   [self.view addSubview:self.webView];
}
-(void)editNavigationBar {
    [self.view addSubview:self.webView];
    NSLog(@"start Load WebView"); 
    [self loadWebView];
}


//load URL
 - (void)loadHTMLNSString *)htmlString titleNSString *)title
 {
    self.request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:htmlString]];
   self.title = title;
   [self.webView loadRequest:self.request];
}

但是日志结果是....

2017-01-22 10:04:48.867 xxx[5404:1574257] start Load WebView

2017-01-22 10:04:48.868 xxx[5404:1584402] myQueue

2017-01-22 10:04:48.868 xxx[5404:1574257] viewLodLoad

2017-01-22 10:04:48.946 xxx[5404:1574257] mainQueue

2017-01-22 10:05:01.547 xxx[5404:1574257] decidePolicyForNavigationAction    

2017-01-22 10:05:01.548 xxx[5404:1574257] didStartProvisionalNavigation

2017-01-22 10:05:02.468 xxx[5404:1574257] decidePolicyForNavigationResponse 



Best Answer-推荐答案


为什么你有所有 GCD 的东西?似乎不需要。您应该能够将其减少到:

- (void)loadWebView {
    [self loadHTML:self.pageModel.url title:self.pageModel.postUser];
}

我敢打赌,这将消除您 10 秒的延迟。

关于ios - 大约 10 秒后开始加载 wkwebview 白页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41786697/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4