我正在为
iphone开发一个基于web的应用程序,我已经为项目创建了新的cssfile,这个css文件不会影响html文件,但是当我上传了css文件一个主机它工作正常并且样式化了html
问题是什么 ?
编辑1
这是头部元素.
css.css工作正常,并正确链接到HTML
jquery.mobile-1.0.min.css不是!
尽管两个文件都存在于同一个边框中
Onotha.com
<link rel="stylesheet" type="text/css" href="css/jquery.mobile-1.0.min.css" />
编辑2
这是Objective-C代码,我有一个例外,我想在最后一行代码中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window makeKeyAndVisible];
NSString *path= [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:NO];
// [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
// NSString *path = [[NSBundle mainBundle] bundlePath];
// NSURL *baseURL = [NSURL fileURLWithPath:path];
// [webView loadHTMLString:htmlString baseURL:baseURL];
// load css styles
NSString *cssPath = [[NSBundle mainBundle] pathForResource:@"css/jquery.mobile-1.0.min.css" ofType:@"css"];
NSData *cssData = [NSData dataWithContentsOfFile:cssPath];
NSString *cssString = [[NSString alloc] initWithData:cssData encoding:NSASCIIStringEncoding];
// load js
NSString *jsPath = [[NSBundle mainBundle] pathForResource:@"MyJS" ofType:@"js"];
NSData *jsData = [NSData dataWithContentsOfFile:jsPath];
NSString *jsString = [[NSString alloc] initWithData:jsData encoding:NSASCIIStringEncoding];
// compose full html page
NSString *pageContent = [NSString stringWithFormat:@"%@%@%@", cssString, jsString, path];
[webView loadHTMLString:pageContent baseURL:baseURL];
return YES;
}
编辑3
使用Srikar发布的代码后我得到了这个
最佳答案 您可以从本地项目目录加载CSS
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[webView loadHTMLString:htmlString baseURL:baseURL];
详细信息检查this site.
这里有更详细的代码 –
// load css styles
NSString *cssPath = [[NSBundle mainBundle] pathForResource:@"MyCSS" ofType:@"css"];
NSData *cssData = [NSData dataWithContentsOfFile:cssPath];
NSString *cssString = [[NSString alloc] initWithData:cssData encoding:NSASCIIStringEncoding];
// load js
NSString *jsPath = [[NSBundle mainBundle] pathForResource:@"MyJS" ofType:@"js"];
NSData *jsData = [NSData dataWithContentsOfFile:jsPath];
NSString *jsString = [[NSString alloc] initWithData:jsData encoding:NSASCIIStringEncoding];
// compose full html page
NSString *pageContent = [NSString stringWithFormat:@"%@%@%@", cssString, jsString, actualPageMarkup];
[webView loadHTMLString:pageContent baseURL:[NSURL URLWithString:@""]];
更多信息here