IOS / Objective-C:强制UIWebView重新加载

时间:2017-07-24 22:34:56

标签: ios objective-c uiwebview

我有一个显示网页视图的屏幕。但是,我允许人们通过更新对象来循环浏览不同的Web视图。当我加载第一页时,Web视图加载正常。但是,当我尝试从viewwillappear中的新对象更新页面时,当其他元素(例如高于webview的标题)加载时,Web视图不会刷新。

//in viewWillAppear
self.title = self.file.imageDescript;//The title loads fine
    NSString *urlBase = @"https://www.~com/images/";
     NSString * imagename = self.file.imagename;
    NSString *url = [NSString stringWithFormat:@"%@%@",urlBase,imagename]; 
    NSURL *realUrl = [NSURL URLWithString:url];
    NSURLRequest *request = [NSURLRequest requestWithURL:realUrl];
    [webView loadRequest:request];



 I have tried various versions of setNeedsDisplay and also applied these to subviews of the web view without success as in this method:


- (void) forceRedrawInWebView:(UIWebView*)webView {
    NSArray *views = webView.scrollView.subviews;

    for(int i = 0; i<views.count; i++){
        UIView *view = views[i];

        //if([NSStringFromClass([view class]) isEqualToString:@"UIWebBrowserView"]){
        [view setNeedsDisplayInRect:webView.bounds]; // Webkit Repaint, usually fast
        [view setNeedsLayout]; // Webkit Relayout (slower than repaint)

        // Causes redraw & relayout of *entire* UIWebView, onscreen and off, usually intensive
        [view setNeedsDisplay];
        [view setNeedsLayout];
        // break; // glass in case of if statement (thanks Jake)
        //}
    }
}

我已经在一个SO回答中读到,自IOS8.2起,UIWebView的刷新不再有效(因为WKWebView)已取代它。我会切换到WKWebView,除了它在故事板中不受支持,显然,我在故事板中有很多东西。

注意:这与刷新相同的网址无关,因为服务器上的内容已更改。它与在UIWebView

中加载完全不同的Web URL有关

有人可以提出解决方法吗?

0 个答案:

没有答案