tags:

views:

463

answers:

1

trouble loading html file from plist to webView using following code in

FAQDetailViewController.m:

- (void)viewDidLoad {
    [super viewDidLoad];

    NSString *Path = [[NSBundle mainBundle] bundlePath];
    NSString *WebPath = [Path stringByAppendingPathComponent:WebFile];
    UIWebView *tempWeb = [[UIWebView alloc] initWithContentsOfFile:WebPath];
    [webView loadData:tempWeb]; //I think my issue is here. I am not understanding how to implement the the code here
    [tempWeb release];
}
loaded here with this peace of code in FAQViewController.m:
FAQDetailViewController *faqdvController = [[FAQDetailViewController alloc] initWithNibName:@"FAQDetailView" bundle:[NSBundle mainBundle]];
faqdvController.WebFile = [dictionary objectForKey:@"faqDesc"]; //html file from plist file placed here
faqdvController.hidesBottomBarWhenPushed = NO;
[self.navigationController pushViewController:faqdvController animated:YES];
[faqdvController release];
A: 

You can try it this way:

NSString *bundle = [[NSBundle mainBundle] bundlePath];
NSString *webPath = [bundle stringByAppendingPathComponent:{htmlFilename}]
UIWebView* browser = [[UIWebView alloc] initWithFrame:
                              CGRectMake(0, 0, 200, 300)];
[browser loadRequest:[NSURLRequest requestWithURL:
                              [NSURL fileURLWithPath:webPath]]];
[self addSubview:browser];

You'll also want to set delegates on the browser so you get informed when the contents have finished loading.

Ramin
Hmmm Confused because im getting my html files from the .plist. So the code you provide will allow mw to do this. Does your code go into the FAQDetailViewController.m file? That is where I setup or path to the html files before calling it in the FAQViewController.m. Im trying your approach now
SympleMyne
another note to be clear... I have a UITableView that loads its data from a .plist similar to Apple’s DrillDownSave sample, and want each cell’s Detail View to load a separate html file. How would I reflect this in the code above
SympleMyne
ok tried it with your code: NSString *Path = [[NSBundle mainBundle] bundlePath]; NSString *WebFile = [Path stringByAppendingPathComponent:webView]; UIWebView *webView = [[UIWebView alloc] initWithFrame: CGRectMake(0, 0, 200, 300)]; [webView loadRequest:[NSURLRequest requestWithURL: [NSURL fileURLWithPath:WebFile]]]; [self addSubview:webView]; however got warnings..thoughts
SympleMyne
What I tried to show is a general method for getting web content from the bundle and showing it in a UIWebView. You can apply it to your specific problem. Not sure why you're passing 'webView' as an html filename and then redeclaring it as a UIWebView. Perhaps that's why you're getting warnings.
Ramin