Go to: uiwebview displaying a network loading

Source: Internet
Author: User

Source: 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> </ptml> ", <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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.