【问题标题】:Trouble loading html file from plist to webView on iPhone在 iPhone 上将 html 文件从 plist 加载到 webView 时遇到问题
【发布时间】:2010-12-06 04:32:28
【问题描述】:

中使用以下代码将 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 发布];

【问题讨论】:

  • coneybeare 你能帮忙吗?我想它应该是
     [webView loadData:tempWeb MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:bundleBaseURL]; 

标签: iphone html plist


【解决方案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];

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

【讨论】:

  • 嗯很困惑,因为我从 .plist 获取我的 html 文件。因此,您提供的代码将允许 mw 执行此操作。您的代码是否进入 FAQDetailViewController.m 文件?那是我在 FAQViewController.m 中调用它之前设置或指向 html 文件的路径。我现在正在尝试你的方法
  • 另一个需要明确的注意事项...我有一个 UITableView,它从类似于 Apple 的 DrillDownSave 示例的 .plist 加载其数据,并希望每个单元格的详细信息视图加载一个单独的 html 文件。我将如何在上面的代码中反映这一点
  • ok 用你的代码试了一下: NSString *Path = [[NSBundle mainBundle] bundlePath]; NSString *WebFile = [路径 stringByAppendingPathComponent:webView]; UIWebView *webView = [[UIWebView alloc] initWithFrame: CGRectMake(0, 0, 200, 300)]; [webView loadRequest:[NSURLRequest requestWithURL: [NSURL fileURLWithPath:WebFile]]]; [自我 addSubview:webView];但是收到警告..想法
  • 我试图展示的是一种从捆绑包中获取 Web 内容并将其显示在 UIWebView 中的通用方法。您可以将其应用于您的特定问题。不知道为什么您将“webView”作为 html 文件名传递,然后将其重新声明为 UIWebView。也许这就是您收到警告的原因。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-10
  • 2017-12-19
  • 1970-01-01
相关资源
最近更新 更多