iOS network Seventh day WebView-04 Imitation NetEase news Details

Source: Internet
Author: User


#import "HMViewController.h"@interfaceHmviewcontroller ()@end@implementationHmviewcontroller- (void) viewdidload{[Super Viewdidload]; //1.url// *url = [Nsurl urlwithstring:@""]; //2.requetsNsurlrequest *request =[Nsurlrequest Requestwithurl:url]; //3. Sending the request[Nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue Mainqueue] completionHandler:^ ( Nsurlresponse *response, NSData *data, Nserror *connectionerror) {Nsdictionary*dict =[nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutableleaves Error:nil]; Nsdictionary*news = dict[@"a7aqot560001124j"];    [Self shownews:news]; }];}- (void) Shownews: (Nsdictionary *) news{//1. Remove Web contentNSString *body = news[@"Body"]; //2. Remove the imageNsdictionary *img = [news[@"img"] Lastobject]; NSString*imghtml = [NSString stringWithFormat:@""%@\"width=\ "300\" height=\ "171\" >", img[@"src"]]; //2. Create a webview to display the Web pageUIWebView *webview =[[UIWebView alloc] init]; Webview.frame=Self.view.bounds;        [Self.view Addsubview:webview]; //3. Splicing Web contentNSString *html = [Body stringbyreplacingoccurrencesofstring:img[@"ref"] withstring:imghtml]; //4. Remove News HeadlinesNSString *title = news[@"title"]; //5. Time to take out newsNSString *time = news[@"Ptime"]; //Head ContentNSString *header = [NSString stringWithFormat:@"<div class=\"Title\">%@</div><div class=\ "time\" >%@</div>", title, Time]; HTML= [NSString stringWithFormat:@"%@%@", header, HTML]; //links to CSS files in MainbundleNsurl *cssurl = [[NSBundle mainbundle] Urlforresource:@"News"Withextension:@"CSS"]; HTML= [NSString stringWithFormat:@"%@<link rel=\"Stylesheet\"href=\ "%@\" >", HTML, Cssurl]; //5. Loading Web content[WebView loadhtmlstring:html baseurl:nil];}@end

iOS network Seventh day WebView-04 Imitation NetEase news Details

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: 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.