【发布时间】:2011-06-24 04:44:53
【问题描述】:
我一直致力于通过捆绑 xib 和下载捆绑包并将 xib 加载到这些捆绑包中,让“自定义换肤”界面适用于我的 iOS 应用程序。
我已按照此处非常有用的说明进行操作,使其几乎可以正常工作。
我下载了包,解压后可以看到 xib 文件。我没有在示例中使用任何 TestViewController 代码,而是在使用刚刚下载的 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];
当我将此视图控制器推送到我的堆栈时,我收到此错误:
*** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法在包中加载 NIB:“NSBundle(尚未加载)”,名称为“CustomDownloadedXib””
问题似乎是我的包“尚未加载”。我尝试通过调用来强制加载我的包:
[bundle load]
但这无济于事。
我的方法不正确吗?这似乎是一种直观的方式。
提前致谢!
【问题讨论】: