解决方法
宏
#define AssertFileExists(path) NSAssert([[NSFileManager defaultManager] fileExistsAtPath:path],@"Cannot find the file: %@",path) #define AssertNibExists(file_name_string) AssertFileExists([[NSBundle mainBundle] pathForResource:file_name_string ofType:@"nib"])
以下是您尝试加载.xib或.nib之前可以调用的一组宏,它们将帮助识别丢失的文件,并发出有关丢失的信息。
解
使用的实际解决方案是:
if([[NSBundle mainBundle] pathForResource:fileName ofType:@"nib"] != nil) { //file found ... }
请注意,该文档说明ofType:应该是该文件的扩展名。不过即使你使用的是.xib,你需要传递“@”nib“或者你会得到一个假阴性。