如何将html加载到webview中?

时间:2012-03-06 23:02:34

标签: xcode uiwebview

我刚刚使用Storyboard重新设计了我的iPhone应用程序... questin是:我如何处理UIWebView以便我可以加载html? (当谈到Obj-C时,我是一个新手,在MonoTouch中完成了我以前的应用程序,所以我有点迷路)。 :d

3 个答案:

答案 0 :(得分:1)

- (void)viewDidLoad {

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

   [webView loadRequest:requestObj];
}

答案 1 :(得分:0)

Apple Developer docs是非常好的资源。这里概述了UIWebView的使用enter link description here

要加载网络资源,只需将NSURLRequest对象传递给loadRequest。

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

您也可以在viewDidLoad中执行此操作(UIWebViewUIView的子类并继承其所有方法)。例如,加载本地pdf资源。

- (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];
    }
}

答案 2 :(得分:0)

要使用链接设置UIWebView,只需使用以下代码。

    var URLPath = "Insert email address here"

然后使用......

    loadAddressURL()

最后......

    func loadAddressURL(){

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

    }
相关问题