图像不从css文件加载
问题描述:
我已经设法在UIWebView中显示HTML,但我的问题是,图像不显示在我的HTML,虽然我的图像,CSS和JavaScript都位于同一个项目文件夹。图像不从css文件加载
这里是我的HTML:
<html>
<head>
<meta name = "viewport" content = "initial-scale = 1.0, user-scalable = no, width = 320"/>
<link rel="stylesheet" type="text/css" href="site.css">
<script src="site.js" type="text/javascript" />
</head>
<body style="margin:0;padding:0;">
<div class="player"></div>
<div class="controller">
<div class="search"></div>
</div>
</body>
</html>
这里是我的CSS:
body{
padding:0;
margin:0;
}
div.player{
width:320px;
height:180px;
}
div.controller{
float:left;
width:320px;
}
div.search{
float:left;
height:40px;
width:320px;
background-image:url('search.jpg');
}
最后,我的Objective-C:
-(void)viewDidLoad {
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSString *htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[navigatorWindow loadHTMLString:htmlString baseURL:baseURL];
NSLog(@"%@",htmlString);
[super viewDidLoad];
}
任何想法是怎么回事这里?
答
确保search.jpg
正在添加到Xcode项目中。我认为这是问题所在,因为它是一个本地html文件,并且不在服务器上托管。希望这可以帮助。
+0
我已经将文件拖入我的xcode项目,并在项目树中可见。这很好 – redoc01 2013-02-09 22:15:51
答
background-image:url('search.jpg');
你必须给这里
@ H2CO3图像的完整路径看起来你忘了从标题中移除的Xcode ...修正为你:) – 2013-03-04 23:35:06
@ RichardJ.RossIII谢谢! :) – 2013-03-05 05:29:20