轉:UIWebView displaying a network loading

來源:互聯網
上載者:User

出處: 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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.