我正在尝试根据运行时的某些条件从子文件夹中加载 NiB 文件。问题是当我调用方法 pathForResource 时代码能够找到 NIB 文件,但是当我运行应用程序时,我总是收到以下错误
由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无法在包中加载NIB:'NSBundle
这是我的代码:
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if(somecondition == true)
{
NSString* nibPath = [[NSBundle mainBundle] pathForResource:nibNameOrNil ofType:@"xib" inDirectory:@"CAS"];
NSString* customPath = [nibPath stringByDeletingLastPathComponent];
NSBundle* localeBundle = [NSBundle bundleWithPath:customPath];
if (localeBundle!= nil) {
nibBundleOrNil = localeBundle;
}
}
}
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
}
return self;
}