Simple application of ios-network Chapter WebView

Source: Internet
Author: User

First, Brief introduction

1. Brief description

UIWebView is an iOS built-in browser control
The system comes with a safari browser that is implemented through UIWebView

UIWebView not only can load remote Web resources, but also can load the most common Files html\htm pdf, doc, ppt, txt mp4 ...

2.UIWebView How to load resources

-(void) Loadrequest: (nsurlrequest *) request;

3. Common Properties and methods

Reload (refresh)-(void) reload;

Stop loading-(void) stoploading;

Fallback-(void) goBack;

Forward-(void) GoForward;

Need to go in? detected data type @property (nonatomic) uidatadetectortypes datadetectortypes

Whether it can be rolled back @property (nonatomic,readonly,getter=cangoback) BOOL cangoback;

Whether it can advance @property (nonatomic,readonly,getter=cangoforward) BOOL CanGoForward;

Whether the @property (nonatomic,readonly,getter=isloading) BOOL loading is being loaded;

Whether to scale the content to fit the screen current size @property (nonatomic) BOOL scalespagetofit;

4. Monitor the UIWebView loading process

Become the agent of UIWebView, obey the Uiwebviewdelegate protocol, can monitor the loading process of UIWebView.

Call this method when you start sending a request (loading data)

-(void) Webviewdidstartload: (UIWebView *) WebView;

Request complete (Load data complete) Si cho? This method

-(void) Webviewdidfinishload: (UIWebView *) WebView;

Call this method when an error is requested

-(void) WebView: (UIWebView *) WebView didfailloadwitherror: (nserror *) error;

5. Monitor the UIWebView loading process

UIWebView before sending the request, will it be transferred? method, if return no, represents a stop load request, returns Yes, representing the Allow load request

-(BOOL) WebView: (UIWebView *) WebView shouldstartloadwithrequest: (nsurlrequest *) Request Navigationtype: ( Uiwebviewnavigationtype) Navigationtype;

Second, basic use

1. Example One

Create a new project and drag a Uiwedview control in the UIView in storyboard.

The simplest to use:

(1) Create a network request

(2) Load network request

Code:

1//2//  YYVIEWCONTROLLER.M 3//  01-uiwebview Basic use 4//5//  Created by Hole Medical has on 14-7-2.6//  Copyright (c) 2014 itcast. All rights reserved. 7//8  9 #import "YYViewController.h" @interface Yyviewcontroller () @property (weak, nonatomic) Iboutlet Uiweb View *webview;13 @end15/**17  *  UIWebView: Browser, can be used to browse common formats of files, such as Html/txt/doc/ppt/mp4 and so on  */19 @ Implementation YYVIEWCONTROLLER20-(void) viewDidLoad22 {     [super viewdidload];24]     //1. Create a network request 26     nsurl *url=[nsurl urlwithstring:@ "http://www.baidu.com"];27     Nsurlrequest *request=[nsurlrequest requestwithurl:url];28     //Load network request     [Self.webview loadrequest : request];31     }33 @end

Simulator Effect:

2. Monitoring UIWebView

code example:

 1//2//YYVIEWCONTROLLER.M 3//01-uiwebview Basic use 4//5//Created by Hole Medical has on 14-7-2. 6//Copyright (c) 2014 itcast. All rights reserved. 7//8 9 #import "YYViewController.h" 10//using a third-party framework #import "Mbprogresshud+mj.h" @interface Yyviewcontroller () <u Iwebviewdelegate>14 @property (Weak, nonatomic) Iboutlet UIWebView *webview;15 @end17/**19 * UIWebView: Browser, can be used To browse common format files such as Html/txt/doc/ppt/mp4 */21 @implementation YYViewController22-(void) viewDidLoad24 {[Super viewd Idload];26 27//1. Create a network request Nsurl *url=[nsurl urlwithstring:@ "http://www.baidu.com"];29 nsurlrequest *reque      St=[nsurlrequest requestwithurl:url];30 31//2. Set the proxy for WebView self.webview.delegate=self;33//scaling content to fit the screen size 34 SELF.WEBVIEW.SCALESPAGETOFIT=YES;35 36//Load Network request PNS [Self.webview loadrequest:request];38}40 #pr Agma mark-uiwebviewdelegate42/**43 *webview Start loading the resource when the call (start sending request) */45-(void) Webviewdidstartload: (UIWebView *) WebView46 {NSLog (@ "Webviewdidstartload---"); [Mbprogresshud showmessage:@ "Loading ..."]; }50/**52 *webview Load completed when the call (request completed) */54-(void) Webviewdidfinishload: (UIWebView *) webView55 {NSLog (@ "Webvie Wdidfinishload---"); Mbprogresshud hidehud];58}59/**61 *webview load failed call (request failed) */63-(void) WebView: (UIWEBV Iew *) WebView didfailloadwitherror: (Nserror *) error64 {NSLog (@ "Didfailloadwitherror---"); [Mbprogresshud hid ehud];67}68 @end

Print View:

Simple application of ios-network Chapter WebView

Related Article

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.