无法将html文件从plist加载到iPhone上的webView

时间:2009-10-13 02:34:24

标签: iphone html plist

使用

中的以下代码将html文件从plist加载到webView时出现问题
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];
}

在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];

1 个答案:

答案 0 :(得分:1)

你可以这样试试:

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

您还需要在浏览器上设置委托,以便在内容加载完成后获得通知。

相关问题