【问题标题】:XCode - (iOS) Calling a local HTML file in to a SplitView via .plist reference?XCode - (iOS) 通过 .plist 引用将本地 HTML 文件调用到 SplitView?
【发布时间】:2011-07-18 08:19:37
【问题描述】:

这里是新手(问题可能很明显),但经过许多小时试图弄清楚这一点后,我已经到了需要寻求帮助的地步......

基本上,我要做的就是从 .plist 中填充的数组中解析一个字符串。此字符串是本地 URL。它非常适用于外部 URL,但无论我为本地 URL 尝试了什么,我得到的都是什么 - 甚至没有找到一个 URL(我撒谎 - 这确实发生过一次,但再也不会被复制)。

我们将不胜感激任何和所有的帮助!

我在 DetailViewController 中有这段代码:

    NSString *attractionURL = [detailItem description];
    NSURL *url = [NSURL URLWithString:attractionURL];
    [wikiView loadRequest:[NSURLRequest requestWithURL:url]];

并且这个代码在一个popOver(RootViewController)中:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.clearsSelectionOnViewWillAppear = NO;
    self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);

    NSBundle *bundle = [NSBundle mainBundle];
    NSString *path = [bundle pathForResource:@"recipes"
                        ofType:@"plist"];
    attractions = [[NSArray alloc] initWithContentsOfFile:path];

    self.title = @"Recipes";

使用 .plist 文件中的 URL:

<array>
    <array>
        <string>Sirloin</string>
        <string>http://Resources/iPad/index.html</string>
    </array>
    <array>
        <string>Chasseur</string>
        <string>http://www.jamesmartinsfood.com</string>
    </array>

</array>
</plist>

就像我说的,外部 URL 工作正常,本地只是不做蹲...

干杯!

【问题讨论】:

    标签: xcode ios ipad ios4 uiwebview


    【解决方案1】:

    您的本地 URL 定义不正确,它不应该有 http://,因为它没有托管在 http 服务器上。

    它应该采用如下格式。

    file://localhost/var/mobile/Application/${APP_ID}/MyApp.app/index.html

    第一部分可能会根据设备/环境不断变化,您需要依赖操作系统框架来确定它,因此在您的 plist 中,您只需定义本地文件的相对路径,然后将提供的路径添加到前面由操作系统。

    类似的东西

    NSString *path = [[NSBundle mainBundle] pathForResource:myFileName ofType:myFileExtension];

    可能对你有用,你 myFileName 是“索引”,myFileExtension 是“html”

    【讨论】:

    • Wangner NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]; NSURL *url=[NSURL URLWithString:path]; NSURLRequest *request=[NSURLRequest requestWithURL:url]; _leafWebView.delegate = self; [_leafWebView loadRequest:request]; 使用上面的代码获取 www.google.com 但不加载本地页面。如果你能指出我错过了什么。提前谢谢
    • @Alix 我认为你应该为此发布一个新问题。
    猜你喜欢
    • 1970-01-01
    • 2011-07-19
    • 1970-01-01
    • 1970-01-01
    • 2014-12-05
    • 2019-01-15
    • 2021-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多