我正在做的项目,我想在图表中显示用户数据..
我想使用webview,html,javascript和css文件显示图形。
在webview中我得到的是桌子而不是图表。我正确获取所有.js和.css文件的文件路径。
我已经在copy Bundle Resources中复制了.js和.css文件。
这是我的代码
NSURL* path = [[NSBundle mainBundle] URLForResource:@"jquery.min" withExtension:@"js"];
NSLog(@"PATH %@",path);
NSURL* path1 = [[NSBundle mainBundle] URLForResource:@"03" withExtension:@"js"];
NSLog(@"PATH %@",path1);
NSURL* css1path = [[NSBundle mainBundle] URLForResource:@"common" withExtension:@"css"];
NSLog(@"CSSPATH %@",css1path);
NSURL* css2path = [[NSBundle mainBundle] URLForResource:@"03" withExtension:@"css"];
NSLog(@"CSS2PATH %@",css2path);
NSString *str = @"<html lang=\"en\">";
str=[str stringByAppendingString:@"<head>"];
str=[str stringByAppendingString:@"<meta charset=\"utf-8\">"];
str=[str stringByAppendingString:@"<meta name=\"viewport\" content=\"width=800\">"];
str=[str stringByAppendingString:@"<title>Sleep Hour Graph of myBeats</title>"];
str=[str stringByAppendingFormat:@"<link rel=\"stylesheet\" href=%@\">",css1path];
str=[str stringByAppendingFormat:@"<link rel=\"stylesheet\" href=%@\">",css2path];
str=[str stringByAppendingString:@"</head>"];
str=[str stringByAppendingString:@"<body>"];
str=[str stringByAppendingString:@"<div id=\"wrapper\">"];
str=[str stringByAppendingString:@"<div class=\"chart\">"];
str=[str stringByAppendingString:@"<h2>Weekly Sleep Graph/Hour</h2>"];
str=[str stringByAppendingString:@"<table id=\"data-table\" border=\"1\" cellpadding=\"10\" cellspacing=\"0\" summary=\"Sleep hours from 2013-08-12 to 2013-08-18\">"];
str=[str stringByAppendingString:@"<caption>Sleep in Hours</caption>"];
str=[str stringByAppendingString:@"<thead>"];
str=[str stringByAppendingString:@"<tr>"];
str=[str stringByAppendingString:@"<td> </td>"];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str1];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str2];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str3];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str4];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str5];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str6];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str7];
str=[str stringByAppendingString:@"</tr>"];
str=[str stringByAppendingString:@"</thead>"];
str=[str stringByAppendingString:@"<tbody>"];
str=[str stringByAppendingString:@"<tr>"];
str=[str stringByAppendingString:@"<th scope=\"row\">Sleep in Hours Per Day</th>"];
str=[str stringByAppendingFormat:@"<td>%@</td>",Str11];
str=[str stringByAppendingFormat:@"<td>%@</td>",Str22];
str=[str stringByAppendingFormat:@"<td>%@</td>",Str33];
str=[str stringByAppendingFormat:@"<td>%@</td>",Str44];
str=[str stringByAppendingFormat:@"<td>%@</td>",Str55];
str=[str stringByAppendingFormat:@"<td>%@</td>",str66];
str=[str stringByAppendingFormat:@"<td>%@</td>",Str77];
str=[str stringByAppendingString:@"</tr>"];
str=[str stringByAppendingString:@"</tbody>"];
str=[str stringByAppendingString:@"</table>"];
str=[str stringByAppendingString:@"</div>"];
str=[str stringByAppendingString:@"</div>"];
str=[str stringByAppendingFormat:@"<script type=\"text/javascript\" src=%@\"></script>",path];
str=[str stringByAppendingFormat:@"<script type=\"text/javascript\" src=%@\"></script>",path1];
str=[str stringByAppendingString:@"</body>"];
str=[str stringByAppendingString:@"</html>"];
NSLog(@"HTMLFINAL %@",str);
[webview loadHTMLString:str baseURL:nil];
[webview stringByEvaluatingJavaScriptFromString:str];
我得到的输出:
期望的输出:
答案 0 :(得分:0)
您的href
和src
属性缺少前导\"
。
str=[str stringByAppendingFormat:@"<link rel=\"stylesheet\" href=%@\">",css1path];
^