SpokaneDude
SpokaneDude

Reputation: 4984

How do I load html into a webview?

I have just re-designed my iPhone app using Storyboard... questin is: how do I address the the UIWebView so I can load the html? (I am a newbie when it comes to Obj-C, having done my previous app in MonoTouch, so I'm kinda lost). :D

Upvotes: 0

Views: 602

Answers (3)

Phillip
Phillip

Reputation: 193

To setup your UIWebView with a link, just use the following code.

    var URLPath = "Insert email address here"

Then use...

    loadAddressURL()

and finally...

    func loadAddressURL(){

        let requestURL = NSURL(string:URLPath)
        let request = NSURLRequest(URL: requestURL!)
        Webview.loadRequest(request)

    }

Upvotes: 0

Peter Kelly
Peter Kelly

Reputation: 14401

Apple Developer docs are really good resource. The usage of UIWebView is outlined here enter link description here

To load a network resource simply pass a NSURLRequest object to loadRequest.

[self.myWebView loadRequest:[NSURLRequest 
    requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"]]];

You can also do this in viewDidLoad (a UIWebView is a subclass of UIView and inherits all its methods). For example, loading a local pdf resource.

- (void)viewDidLoad {
    [super viewDidLoad];

    NSString *thePath = [[NSBundle mainBundle] pathForResource:@"iPhone_User_Guide" ofType:@"pdf"];
    if (thePath) {
        NSData *pdfData = [NSData dataWithContentsOfFile:thePath];
        [(UIWebView *)self.view loadData:pdfData MIMEType:@"application/pdf"
            textEncodingName:@"utf-8" baseURL:nil];
    }
}

Upvotes: 0

slayerIQ
slayerIQ

Reputation: 1486

- (void)viewDidLoad {

   NSString *urlAddress = @”http://www.stackoverflow.com”;
   NSURL *url = [NSURL URLWithString:urlAddress];
   NSURLRequest *req = [NSURLRequest requestWithURL:url];

   [webView loadRequest:requestObj];
}

Upvotes: 1

Related Questions