找出XIB在运行时是否存在

Fra*_*ano 1 macos cocoa xib nsbundle ios

反正有做吗?

我已经尝试过pathForResource:ofType:NSBundle,但它确实存在时找不到xib。如果我尝试加载它,但它不存在loadNibNamed:owner:options:崩溃,那么也会崩溃nibWithNibName:bundle:

基本上,我想在运行时知道是否应该为集合视图上给定单元格类型注册xib或仅注册一个类。

T. *_*sen 5

您确定pathForResource:ofType:不起作用吗?不仅仅是常见的xib / nib混淆?

(.xib文件是ofType:@"nib")...

NSBundle *mainBundle = [NSBundle mainBundle];
NSString *path = [mainBundle pathForResource:@"crapXib" ofType:@"nib"]; // file is called crapXib.xib
if (path){
    // whatever...
} else{
    // whatever else
}
Run Code Online (Sandbox Code Playgroud)