问题
Hi I'm a have an app in which i load webpage in a uiwebview .So each time it takes too much time for loading . So i need to load the webpage in a background mode. Any one know how to done this.
Any help would be appreciable.
回答1:
- (void) start_Web_View {
UIWebView *wv = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,460)];
wv.delegate = self;
[wv loadRequest:
[NSURLRequest requestWithURL:
@"http://long_loading_web_site"]];
// go do something else to amuse the user while the web site loads...
}
#pragma mark webview delegate
- (void) webViewDidFinishLoad:(UIWebView *)webView {
[self.view addSubview: webView]; // load is done, so add the webview to self.view so it's visible.
}
回答2:
Do you want to pre-load that other URL, so when it loads in the main webView it loads faster (or it's already loaded)?
You could create another UIWebView and don't show it at all, and make it load the other URL (you can set the frame of it outside the screen bounds).
Example:
UIWebView *dummyWebView = [[UIWebView alloc] init];
dummyWebView.frame = CGRectMake(-1, -1, 1, 1);
来源:https://stackoverflow.com/questions/7418815/background-loading-a-url-in-a-uiwebview