Knowledge Supplement One. Dictionary to model, use of WebView

Source: Internet
Author: User

A. Dictionary to model (this method is used later)

//defined in Model.h
-(Instancetype) Initwithdictionary: (Nsdictionary *) Dict;

//In MODEL.M -(Instancetype) Initwithdictionary: (Nsdictionary *) dict{if(self =[Super Init]) {[Self setvaluesforkeyswithdictionary:dict]; } returnSelf ;}
//Setvalue:forundefinedkey: A must-write method in model.m -(void) SetValue: (ID) value Forundefinedkey: (NSString *) key{ // if ([Key isequaltostring:@ "id"]) {//Self.movieid = value; // }}

//Call Newsmodel*model = [[Newsmodel alloc] initwithdictionary:dict];

Two. Use of WebView

<UIWebViewDelegate>@property (nonatomic, strong) UIWebView*WebView, @property (nonatomic, strong) Uiactivityindicatorview*Activityindicator;//Initialize UIWebView_webview =[[UIWebView alloc] initWithFrame:self.view.frame]; Nsurlrequest*request = [Nsurlrequest requestwithurl:[nsurl urlwithstring:@"http://baidu.com"]];    [Self.view Addsubview:_webview]; [_webview loadrequest:request];//UIWebView has 3 agent methodologies to follow the Uiwebviewdelegate protocolSelf.webview.Delegate=Self ;#pragma-mark webviewdelegate//determine whether to load before loading-(BOOL) WebView: (UIWebView *) WebView shouldstartloadwithrequest: (Nsurlrequest *Request Navigationtype: (uiwebviewnavigationtype) navigationtype{returnYES;}- (void) Webviewdidstartload: (UIWebView *) webview{NSLog (@"Web page starts loading");//a daisy appears on the load waiting page//creating a back-end translucent viewUIView *view =[[UIView alloc] initWithFrame:self.view.frame]; View.tag=108; View.backgroundcolor=[Uicolor Blackcolor]; View.alpha=0.5; [Self.view Addsubview:view];//Initialize UiactivityindicatorviewSelf.activityindicator = [[Uiactivityindicatorview alloc] Initwithframe:cgrectmake (0,0,0,0)];    [View AddSubview:self.activityIndicator]; Self.activityIndicator.center=View.center;//set the style of UiactivityindicatorviewSelf.activityIndicator.activityIndicatorViewStyle =Uiactivityindicatorviewstylewhitelarge;//Start Display[Self.activityindicator startanimating];}- (void) Webviewdidfinishload: (UIWebView *) webview{NSLog (@"Web page loading complete");//Find and remove a view by tag valueUIView *view = [Self.view viewwithtag:108]; [View Removefromsuperview];}- (void) WebView: (UIWebView *) WebView didfailloadwitherror: (Nserror *) error{NSLog (@"page loading error, error:%@", error); UIView*view = [Self.view viewwithtag:108]; [View Removefromsuperview];}

Knowledge Supplement One. Dictionary to model, use of WebView

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.