How to use WebView

Source: Internet
Author: User


-(Ibaction) testloadhtmlsting: (ID) Sender {//Set the basic path of the home file//file named "index.html"//[NSBundle Mainbundle] is to get the current project address    NSString *htmlpath = [[NSBundle mainbundle]pathforresource: @ "index" oftype:@ "html"];    Get HTML resource path Nsurl *bundleurl = [Nsurl fileurlwithpath:[[nsbundle mainbundle] Bundlepath]];        Nserror *error = nil;        You must specify a character set when you specify the coded character set, and then load the Htmlpath into the encoding//loading WebView! Storing the contents of HTML in nsstring nsstring *html = [[NSString alloc] Initwithcontentsoffile:htmlpath Encoding:nsutf8stringencodin    G error:&error];    if (Error = = nil) {//loadhtmlstring used to get the path of the HTML [Self.webview loadhtmlstring:html Baseurl:bundleurl]; }}-(Ibaction) Testloaddata: (ID) Sender {//Set home page file! The basic path to load the home page data via an HTML string nsstring *htmlpath = [[NSBundle Mainbu        Ndle] pathforresource:@ "index" oftype:@ "html"];    Gets the resource path of the home file Nsurl *bundleurl = [Nsurl fileurlwithpath:[[nsbundle mainbundle] Bundlepath]];  Nserror *error = nil;      Here is nsdata nsdata *htmldata = [[NSData alloc] initwithcontentsoffile:htmlpath]; if (Error = = nil) {//because it is nsdata you need to specify the character set UTF-8 [Self.webview loaddata:htmldata mimetype:@ "text/html" Textenc    odingname:@ "UTF-8" baseurl:bundleurl]; }}-(ibaction) Testloadrequest: (ID) Sender {//string saved as Nsurl nsurl *url = [Nsurl urlwithstring:@] Http://www.51work6    . com "];    Initiates an asynchronous request nsurlrequest *request = [Nsurlrequest Requestwithurl:url];    [Self.webview Loadrequest:request]; Self.webView.delegate = self;}


How to use 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.