简体   繁体   中英

Why is this dynamically generated HTML not being displayed in a UIWebView?

I have HTML I am generating in my app. I know it's valid because I ran it through W3Schools "edit and try it". It performs exactly as I designed it.

Here is the definition of the website in the header file:

@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

Here is where I finish creating the HTML and try to display it:

        //  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]]];
}

As you can see, I have tried several different variations of displaying the HTML string. What is the correct way to do this?

Iulius Caesar Jacques Cousteau gave the correct answer in a comment :

reportWebView is an IBOutlet , indicating that it's created in an xib. Is the outlet connected? Is the nib loaded? What's with the commented-out UIWebView *reportWebView = [[UIWebView alloc] init]; ? Is this your exact code? Are you creating a local variable reportWebView that's shadowing the ivar?

but never came back to set it, therefore I am answering it for him.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM