0

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

1 に答える 1

1

NIB / XIB を xCode プロジェクトに含める必要があります。それらは同じフォルダーにある必要があります。プロジェクトにインポートされたNIB / XIBのみをロードできます。

于 2011-11-18T02:24:06.763 に答える