【问题标题】:Load image/link in UIWebview在 UIWebview 中加载图像/链接
【发布时间】: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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2012-08-19
    • 1970-01-01
    • 1970-01-01
    • 2011-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-05
    • 1970-01-01
    相关资源
    最近更新 更多