加载本地网页iphone sdk?

时间:2013-09-12 13:05:46

标签: iphone uiwebview ios4

大家好,我的iphone应用程序中有一个本地网站,带有images / css / jquery。如果我从我的电脑浏览器打开html文件,它会打开所有内容。enter image description here

这是我在uiwebview中加载html内容的代码,该代码无效。

/    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"html" inDirectory:@"HTML1"]];
//    NSURLRequest *request = [NSURLRequest requestWithURL:url];
//    [_webView loadRequest:request];
//    [super viewDidLoad];

    NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]];
    NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"html" inDirectory:@"HTML1"];
    NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];
    [_webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:baseURL];

以上都没有工作蚂蚁帮助:)?

1 个答案:

答案 0 :(得分:0)

试试这个将test.html直接放在Pages-HTML文件夹下...... 然后在UIWebview中加载html文件使用代码...

    // to load html file from the bundle
    NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"helpfile" ofType:@"html"];
    NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];
    NSString *path = [[NSBundle mainBundle] bundlePath];
    NSURL *baseURL = [NSURL fileURLWithPath:path];
    [self.webVw loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:baseURL];