我有我在我的应用程序中生成的HTML。我知道这是有效的,因为我通过W3Schools“编辑并尝试它”来运行它。它完全按照我的设计执行。为什么这个动态生成的HTML不会显示在UIWebView中?
这里是在头文件的网站的定义:
@interface ReportViewController : UIViewController <UIWebViewDelegate> {
IBOutlet UIWebView *reportWebView;
}
@property (nonatomic, retain) UIWebView *reportWebView;
@property (nonatomic, retain) NSMutableString *html;
- (void) generateReport;
- (void) Alert: (NSString *) title andData: (NSString *) errorMsg;
@end
这里是我完成创建HTML,并尝试以显示它:
// now do the table
[html appendString:@"<div><table border class=\"boldtable\">"
"<tr BGCOLOR=\"ADDAFE\">"
"<th>STA </th><th>BS </th><th>HI </th><th>FS </th><th>ELEV </th><th>Desc</th>"
"</tr><p>"];
}
// finally, end the table, etc.
[html appendString:@"</table></div></body></html>"];
// UIWebView *reportWebView = [[UIWebView alloc] init];
//[reportWebView loadHTMLString: html baseURL:nil];
[self.reportWebView loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
}
正如你所看到的,我已经尝试了几种不同的显示HTML字符串的变体。什么是正确的方法来做到这一点?
你在哪里追加字符串?是否过了关闭
标签也许? – Lefteris 2012-04-18 20:01:54不,最终的HTML字符串是有效的,正如我最初提到的。我相信这与我试图在UIWebView中显示它的方式有关。我之前使用文本文件完成了此操作,但从未使用动态生成的HTML。 – SpokaneDude 2012-04-18 20:09:27
为什么不尝试用JavaScript插入它?您可以使用adjacentHTML dom方法来插入html ... – Lefteris 2012-04-18 20:12:23