加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – 检查.nib或.xib文件是否存在

发布时间:2020-12-15 02:05:27 所属栏目:百科 来源:网络整理
导读:在尝试使用initWithNibName:bundle或类似文件加载之前,检查Nib或Xib文件是否存在的最佳方式是什么? 解决方法 宏 #define AssertFileExists(path) NSAssert([[NSFileManager defaultManager] fileExistsAtPath:path],@"Cannot find the file: %@",path)#de
在尝试使用initWithNibName:bundle或类似文件加载之前,检查Nib或Xib文件是否存在的最佳方式是什么?

解决方法

#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“或者你会得到一个假阴性。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读