iOS:强制UIWebView重新加载/阻止缓存

时间:2012-06-09 15:33:00

标签: objective-c ios5 uiwebview

我有一个显示网站的iPhone应用程序。这个网站不时更改它的内容,但我的应用程序不会在每次打开时重新加载它。我试图阻止网站的缓存,但没有成功。

这是我的init方法:

- (id)init:(NSString *)url withTitle:(NSString *)theTitle withPageName:(NSString *)pageName {
    self = [super init];
    if(self) {
        NSLog(@"websiteviewcontroller init");
        self.title = theTitle;
        self.url = url;
        self.pageName = pageName;

        CGRect frame = [[UIScreen mainScreen] applicationFrame];
        webView = [[UIWebView alloc] initWithFrame:frame];

        NSURL *theURL = [NSURL URLWithString:url];
        [webView loadRequest:[NSURLRequest requestWithURL:theURL]]; 

        // support zooming
        webView.scalesPageToFit = YES;

                //[[NSURLCache sharedURLCache] removeAllCachedResponses];
                [webView reload];

    }
    return self;
}

这是我的viewWillAppear-Method:

- (void)viewWillAppear:(BOOL)animated {

    CGRect frame = [[UIScreen mainScreen] applicationFrame];
    webView = [[UIWebView alloc] initWithFrame:frame];

    NSURL *theURL = [NSURL URLWithString:url];
    [webView loadRequest:[NSURLRequest requestWithURL:theURL]]; 

    [webView reload];

    // support zooming
    webView.scalesPageToFit = YES;
}

请帮我解决这个问题。所有答案都非常感谢。

2 个答案:

答案 0 :(得分:11)

此代码段解决了我的问题:

[[NSURLCache sharedURLCache] removeAllCachedResponses];

答案 1 :(得分:0)

答案仅适用于下一个问题。对于一个完整的答案: UIwebview without Cache

相关问题