iOS - 从Documents目录中的bundle加载xib [英] iOS - loading xib from bundle in Documents directory

查看:368
本文介绍了iOS - 从Documents目录中的bundle加载xib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直致力于通过捆绑xib和下载软件包以及在这些软件包中加载xib来为我的iOS应用程序提供自定义skinnable界面。

I've been working on getting "custom skinnable" interfaces working for my iOS app by bundling up xibs and downloading bundles, and loading the xibs in those bundles.

我已按照这里非常有用的说明进行操作。

I have followed the very useful instructions here to get it almost working.

在iOS上加载NSBundle文件

我有捆绑下载,解压缩并可以看到xib文件。我没有在示例中使用任何TestViewController代码,但是在使用刚下载的xib创建视图控制器时这样做:

I have the bundle downloading, and unzipping and can see the xib file. I have not used any of the TestViewController code in the example, but am instead doing this when creating the view controller using the just downloaded xib:

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"gg.bundle"];
    NSBundle *bundle = [NSBundle bundleWithPath:filePath];

    if ( !bundle )
    {
        NSLog(@"Error getting bundle");
    }

    MyViewController *vc = [MyViewController new];
    [vc initWithNibName:@"CustomDownloadedXib" bundle:bundle];

当我将此视图控制器推送到我的堆栈时,我收到此错误:

When I go to push this view controller onto my stack, I get this error:

***因未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无法在bundle中加载NIB:'NSBundle(尚未加载)',名称为'CustomDownloadedXib''

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (not yet loaded)' with name 'CustomDownloadedXib''

问题似乎是我的包尚未加载。我尝试通过调用强制我的包加载:

The issue seems to be that my bundle is "not yet loaded." I tried forcing my bundle to load by calling:

[bundle load]

但这没有帮助。

我的方法在这里不正确吗?这似乎是直观的方式。

Is my approach here incorrect? This seems like the intuitive way to do it.

提前致谢!

推荐答案

按照这里的说明工作:

在iOS上加载NSBundle文件

我只是错误地创建了捆绑包!

I was just creating the bundle incorrectly!

您需要在Xcode中创建捆绑包,因为如果不这样做,它将不会被加载。要创建向项目添加新目标,请选择框架和。库 - >捆绑,并链接到Core Foundation。然后将要上载的xib添加到目标网站。构建目标,在Finder中显示它,压缩并上传!

You need to create the bundle in Xcode though because if you don't, it won't be loaded. To create, Add a New Target to your project, choose Framework & Library -> Bundle, and link to Core Foundation. Then add the xibs you want to upload to the web to the target. Build target, reveal it in Finder, compress, and upload!

这篇关于iOS - 从Documents目录中的bundle加载xib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆