0

我有在我的应用程序中生成的 HTML。我知道它是有效的,因为我通过 W3Schools “编辑并尝试”运行它。它的性能完全符合我的设计。

这是头文件中网站的定义:

@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&nbsp;</th><th>BS&nbsp;</th><th>HI&nbsp;</th><th>FS&nbsp;</th><th>ELEV&nbsp;</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 字符串的变体。这样做的正确方法是什么?

4

1 回答 1

0

尤利乌斯·凯撒Jacques Cousteau在评论中给出了正确答案:

reportWebViewIBOutlet,表示它是在 xib 中创建的。插座是否连接?笔尖是否已加载?注释掉的内容是UIWebView *reportWebView = [[UIWebView alloc] init];什么?这是您的确切代码吗?您是否正在创建一个reportWebView隐藏 ivar 的局部变量?

但从未回来设置它,因此我为他回答了它。

于 2012-04-23T17:56:31.680 回答