How to add "loading" screen for UIWebView app each time new page is being loaded?
I have an app that works with tabs and webview. I already have it setup to refresh the page assigned to a tab each time the item on tabbar is selected. My problem now is that it takes some time to load the page and it开发者_Python百科's impossible to say if the page being displayed is the old or refreshed one.
What I want to do is add a "loading" screen (a simple image) which will be displayed until the refreshed page is loaded. Here is the function I run on each tab tap:
- (void) goToPage:(NSString *)sid
{
NSString *newURL = [NSString stringWithFormat:@"%@/mykingdom.php?sid=%@", appURL, sid];
[secondView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:newURL]]];
}
Thanks!
UIWebViewDelegate has 2 handy methods:
– webViewDidStartLoad:(UIWebView *)webView
– webViewDidFinishLoad:(UIWebView *)webView
you can easy implement and do whatever you like. Cheers,
The preferred UI is to show a large UIActivityIndicatorView. That is the "gear" that rotates a highlight as if turning.
If you wanted something else, you could just display a modal view over the UIWebView with some graphic in it and then dismiss it when the web view reports itself done loading.
If you wanted a web view to display something, the easiest way would be to have to web views one showing the loading page and the other loading the actual page. Swap them out as needed. That gets around having to manage the downloading to a string then loading into a web view which can sometimes get messy for complex web sights.
精彩评论