0621. Displaying HTML data with WebView

Source: Internet
Author: User

1. Create and load the UIWebView in the Loadview method first

-(void) loadview{    [[UIWebView alloc]init];//So there will only be one view} on the controller

2. Set the execution path of the WebView

-(void) viewdidload{    [Super Viewdidload];    3, loading web interface    UIWebView *webview = (UIWebView *) Self.view;    Webview.delegate = self;//    3.1 Gets the full path of the file    nsstring *fullpath = [[NSBundle mainbundle]pathforresource: self.helpModel.html oftype:nil];//    3.2 Get URL    nsurl * url = [[Nsurl alloc]initfileurlwithpath:fullpath];//    3.3 Get Request    nsurlrequest *request = [[nsurlrequest alloc]initwithurl:url];//    3.4 load    [WebView Loadrequest:request]; }

3. When the page is loaded, execute the JavaScript code and jump to the corresponding location

In the WebView proxy method--webviewdidfinishload inside the execution

    Generate the corresponding JavaScript code    nsstring *jsstr = [NSString stringwithformat:@ "window.location.href = ' #%@ ';", SELF.HELPMODEL.TAGID];    Stringbyevaluatingjavascriptfromstring:jsstr];

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.