1

使用以下代码将 html 文件从 plist 加载到 webView 时遇到问题

FAQDetailViewController.m:

- (void)viewDidLoad {
    [超级视图DidLoad];

    NSString *Path = [[NSBundle mainBundle] bundlePath];
    NSString *WebPath = [路径 stringByAppendingPathComponent:WebFile];
    UIWebView *tempWeb = [[UIWebView alloc] initWithContentsOfFile:WebPath];
    [webView 加载数据:tempWeb];//我想我的问题就在这里。我不明白如何在这里实现代码
    [tempWeb发布];
}

在这里加载了 FAQViewController.m 中的代码:

FAQDetailViewController *faqdvController = [[FAQDetailViewController alloc] initWithNibName:@"FAQDetailView" bundle:[NSBundle mainBundle]];
faqdvController.WebFile = [字典 objectForKey:@"faqDesc"]; //来自plist文件的html文件放置在这里
faqdvController.hidesBottomBarWhenPushed = NO;
[self.navigationController pushViewController:faqdvController Animation:YES];
[faqdvController 发布];
4

1 回答 1

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

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

于 2009-10-13T04:23:14.560 回答