如果你還沒有得到它的工作,這裏是一個工作的例子。它還會在加載失敗時顯示警報,並且警報僅顯示一次。
頁眉:
@interface MyViewController : UIViewController <UIWebViewDelegate> {
BOOL wasLoaded;
BOOL alertWasShown;
}
@property (nonatomic, retain) IBOutlet UIWebView *myWebView;
@end
實現:
- (void)loadWebView:(NSString *)urlString {
if (wasLoaded == NO) {
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *requestObject = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:requestObject];
}
}
- (void)viewWillAppear:(BOOL)animated {
NSString *urlString = @"put your url here";
[self loadWebView:urlString];
}
- (void)viewDidLoad {
[super viewDidLoad];
wasLoaded = NO;
alertWasShown = NO;
myWebView.delegate = self;
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
// Not necessary to do anything here.
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
wasLoaded = YES; // Indicates that it finished loading.
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
if (alertWasShown == NO) {
UIAlertView *alert = ... // Create an alert.
[alert show];
alertWasShown = YES;
}
}
我希望幫助。
唯一的解決辦法(我發現)這工程確定:http://stackoverflow.com/questions/1662565/uiwebview-finished-loading-event/25620001# 25620001 – sabiland