1

Resources からの画像を使用して以下のように infoPage.html を呼び出し、html で img src="eye.png" として参照されています。テキストは正しく表示されますが、画像を読み込めません (? のみが表示されます)。 .

- (void)viewDidLoad {

 [super viewDidLoad];

 CGRect webRect = CGRectMake(15,40,300,450);
 UIWebView *myWebView = [[UIWebView alloc] initWithFrame:webRect];

 myWebView.delegate = self;

 myWebView.scalesPageToFit = NO;
 NSString *htmlPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"infoPage.html"];
 NSString *htmlContent = [NSString stringWithContentsOfFile:htmlPath];
 [myWebView loadHTMLString:htmlContent baseURL:nil]; 

 //stop webview from scrolling
 [[[myWebView subviews] lastObject] setScrollingEnabled:NO];

 [myWebView loadHTMLString:htmlContent baseURL:nil];

 [self.view addSubview:myWebView];

 [myWebView release];
}
4

2 に答える 2

3

画像を抽出する場所を認識できるように、-loadHTMLではなく[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:htmlPath]]]を使用する必要があります。または、パスをbaseURL:引数として渡すこともできます。

于 2009-11-16T23:54:57.910 に答える
1

baseURL:nil の代わりに、baseURL:[NSURL URLWithString:[[NSBundle mainBundle] bundlePath]]] を試してください。

于 2009-11-17T00:20:51.287 に答える