出處: http://snipplr.com/view/29213/uiwebview-displaying-a-network-loading/
URL: http://www.iphonedevsdk.com/forum/iphone-sdk-development-advanced-discussion/15077-uiwebview-not-calling-webviewdidfinishload.html
This works fine on my app.
#import <UIKit/UIKit.h></p><p>@interface className : UIViewController <UIWebViewDelegate>{<br />UIWebView*myWebView;<br />}<br />@end</p><p>#import "className.h"<br />@implementation className<br />// Implement loadView to create a view hierarchy programmatically, without using a nib.<br />- (void)loadView {<br />UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];<br />self.view = contentView;</p><p>CGRect webFrame = [[UIScreen mainScreen] applicationFrame];<br />webFrame.origin.y = 0.0;<br />myWebView = [[UIWebView alloc] initWithFrame:webFrame];<br />myWebView.backgroundColor = [UIColor whiteColor];<br />myWebView.scalesPageToFit = YES;<br />myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);<br />myWebView.delegate = self;<br />[self.view addSubview: myWebView];<br />[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com/"]]];<br />}<br />#pragma mark UIWebView delegate methods<br />- (void)webViewDidStartLoad:(UIWebView *)webView<br />{<br />// starting the load, show the activity indicator in the status bar<br />[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;<br />}<br />- (void)webViewDidFinishLoad:(UIWebView *)webView<br />{<br />// finished loading, hide the activity indicator in the status bar<br />[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;<br />}<br />- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error<br />{<br />// load error, hide the activity indicator in the status bar<br />[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;</p><p>// report the error inside the webview<br />NSString* errorString = [NSString stringWithFormat:<br /> @"<html><center><font size=+5 color='red'>An error occurred:<br>%@</font></center></html>",<br /> error.localizedDescription];<br />[myWebView loadHTMLString:errorString baseURL:nil];<br />}<br />- (void)didReceiveMemoryWarning {<br /> [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview<br /> // Release anything that's not essential, such as cached data<br />}</p><p>- (void)dealloc {<br /> [super dealloc];<br />}</p><p>@end