Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have searched on S/O and none of the answers have applied to my code so I am assuming its something I am missing in my code.

I added a UIWebView using Interface Builder called showAbout

I declared an iVar with an IBOutlet here:

@interface About : UIViewController<UIWebViewDelegate>
{
   IBOutlet UIWebView *showAbout;
}


@property (nonatomic, retain) IBOutlet UIWebView *showAbout;

I verified that InterfaceBuilder does in fact have an outlet set for it.

Here is how I am setting it up in the about.m

 showAbout.scalesPageToFit = YES;
    NSString *thePath = [[NSBundle mainBundle] pathForResource:@"about" ofType:@"html"];
    if (thePath) {
        NSData *aboutData = [NSData dataWithContentsOfFile:thePath];
        [showAbout loadData:aboutData MIMEType:@"application/html"
                        textEncodingName:@"utf-8" baseURL:nil];

The UIWebView is not displaying my HTML page that I have added to the project.

Any ideas...

share|improve this question
    
stackoverflow.com/questions/6263289/… may be your problem. –  user2579943 Jul 14 '13 at 20:24
1  
is aboutData nil? –  Paul Cezanne Jul 23 '13 at 22:54
    
@PaulCezanne, I didnt set up this bounty from my mac... will check tonight and advise. –  logixologist Jul 23 '13 at 22:56
    
@PaulCezanne aboutData is not nil. It actually finds the html file because it shows 118 bytes. (or its finding some file) –  logixologist Jul 24 '13 at 6:14
    
Thank you all for helping out with this. It turns out it was a very easy MIME Type issue. Though the changing it to an NSString was an option, the MIME type change offered by @omz was the best solution for me because it was the least amount of code to change. –  logixologist Jul 24 '13 at 16:22

3 Answers 3

up vote 1 down vote accepted
+50

The correct MIME type for HTML is text/html, not application/html, so you should use that for the MIMEType argument.

Alternatively, you could also convert your NSData object to an NSString and use the loadHTMLString:baseURL: method of UIWebView.

share|improve this answer

probably it is better to use NSString and load html document as follows:

ViewController.h file

@property (retain, nonatomic) IBOutlet UIWebView *webView;

make sure that property is connected to webView in XIB/StoryBoard

ViewController.m file

 NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"about" ofType:@"html"];
    NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
    [self.webView loadHTMLString:htmlString baseURL:nil];
share|improve this answer

In .h file you need initial a webview outlet

    IBOutlet UIWebView *_wvSetting;            

In .m file

        NSString htmlContent = nil;
        htmlContent = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"about" ofType:@"html"] encoding:NSUTF8StringEncoding error:nil];
        [_wvSetting loadHTMLString:htmlContent baseURL:nil];
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.