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

nim*_*rod 8 objective-c uiwebview ios5

我有一个显示网站的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;
}
Run Code Online (Sandbox Code Playgroud)

这是我的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;
}
Run Code Online (Sandbox Code Playgroud)

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

nim*_*rod 11

这段代码snipplet解决了我的问题:

[[NSURLCache sharedURLCache] removeAllCachedResponses];
Run Code Online (Sandbox Code Playgroud)