【问题标题】:webview(wkWebView) ios startProvisionalnavigation on the main threadwebview(wkWebView) ios startProvisionalnavigation 在主线程上
【发布时间】:2018-03-16 05:54:28
【问题描述】:

我需要在主线程上运行 webview(WKWEbView)。我正在使用 dispatch_get_main_queue 取得成功。

  dispatch_async(dispatch_get_main_queue(), ^{


        [thisClass alertView]; // alertview method show a webview..
    });

//webview 完美地显示在应用程序上。

现在,我想在打开 web 视图之前放置进度条(渲染过程)。作为 以下方法的主线程上的个人工作正常。 但是我的 webView 在另一个线程中。

如何调用以下方法或使用 webView(WKWEbView)

附加到该方法
-(void)webView:webView didFinishNavigation:(WKNavigation *)navigation{
    NSLog(@"Call ::didFinishNavigation");
    [indicator stopAnimating];
}


-(void)webView:webView didStartProvisionalNavigation:(WKNavigation *)navigation{
    NSLog(@"Call :: webViewDidStartLoad");
    indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    indicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
    indicator.center = self.view.center;
    [self.view addSubview:indicator];
    [indicator bringSubviewToFront:self.view];
    [UIApplication sharedApplication].networkActivityIndicatorVisible = TRUE;
    [indicator startAnimating];
}

问题1:是否可以从另一个线程中获取所有默认方法?

问题 2:问题 1 -> 是的,如何?

【问题讨论】:

  • “但是我的 webView 在另一个线程中”是什么意思。据我所知,您正在使用 dispatch_async(dispatch_get_main_queue() 加载 Web 视图,因此您的 Web 视图正在主线程上加载,您的活动指示器也是如此。有什么问题?
  • 先试试这个而不是我的回答 [self.view addSubview:indicator];用 [self.videowebView addSubview: indicator] 改变它;
  • @SandeepBhandari ,webview 正在加载,但指标未加载。我检查了日志,didStartProvisionalNavigation 和 didFinishNavigation 方法都没有为此工作。

标签: ios objective-c webview uiwebview


【解决方案1】:

不,这是不可能的。即使它会工作有时,如果您通过 App Store 分发您的应用程序,您也会在崩溃日志中收到奇怪的错误。您应该始终在主线程中运行所有 UIKit 和 WebKit 操作。

【讨论】:

    猜你喜欢
    • 2016-09-25
    • 2016-03-25
    • 1970-01-01
    • 2011-09-06
    • 2012-07-19
    • 2015-04-07
    • 2021-02-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多