在UIWebview中加载图像/链接

时间:2013-12-16 04:09:24

标签: ios objective-c uiwebview

尝试将html文件加载到webview中,该文件包含链接到支持文件文件夹中其他页面的图像。加载主html文件,但图像和链接不起作用。有关如何解决这个问题的任何建议?我将我的img文件称为img src =“$#%。png”。

- (void)viewDidLoad {
    [super viewDidLoad];

    NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"iphone" 
        ofType:@"html"];
    NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile
        encoding:NSUTF8StringEncoding error:nil];
    NSString *path = [[NSBundle mainBundle] bundlePath];
    NSURL *baseURL = [NSURL fileURLWithPath:path];
    [myWebView loadHTMLString:htmlString baseURL:baseURL];      
    [myWebView loadHTMLString:htmlString baseURL:[[NSBundle mainBundle] 
        bundleURL]];    
    [myWebView loadHTMLString:htmlString baseURL:nil];  
}

1 个答案:

答案 0 :(得分:0)

使用此代码在html中加载UIWebView文件:

 [myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"iphone" ofType:@"html"] isDirectory:NO]]];