実行時の条件に基づいて、サブフォルダーから 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;
}