Nathan Cleary
Nathan Cleary

Reputation: 653

Trouble loading a local HTML file in UIWebView

I'm trying to load a local HTML file from my supporting files folder in my project... I keep getting this message... Thread 1: breakpoint 1.1 and I don't know why, my code for the web view is below

#import "WPViewController.h"

@interface UIViewController ()

@end

@implementation WPViewController

@synthesize viewWeb;

- (void)viewDidLoad {

[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"  inDirectory:@"localHTML"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[viewWeb loadRequest:request];
}

 - (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (IBAction)dismissView:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}

@end

Header...

#import <UIKit/UIKit.h>

@interface WPViewController : UIViewController

@property (strong, nonatomic) IBOutlet UIWebView *viewWeb;

- (IBAction)dismissView:(id)sender;

@end

Upvotes: 0

Views: 749

Answers (2)

Alejandro Benito-Santos
Alejandro Benito-Santos

Reputation: 2069

First, double check you haven't set any breakpoints that are stopping your app. You can disable/enable them using CMD+Y. Also, you can see if you have set any at all on the left pane -> Breakpoint Navigator tab.

Also, you should try to implement the UIWebViewDelegate protocol and override

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error

in your WPViewController so you can obtain some more info on why the page isn't being displayed.

Upvotes: 1

Vikas S Singh
Vikas S Singh

Reputation: 1766

try may be helped you..

- (void)viewDidLoad {

[super viewDidLoad];

NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"html_files"];

NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];
webView = [UIWebView alloc] init];
[webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]];

}

Upvotes: 0

Related Questions