【发布时间】:2013-12-16 04:09:23
【问题描述】:
尝试将 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];
}
【问题讨论】:
-
试试这个 [myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"iphone" ofType:@"html"]isDirectory:NO]]];
-
加入回答干杯!!!
标签: ios objective-c uiwebview