iOS开发 [NSBundle mainBundle] 通过pathForResource返回路径为空.
2017-06-26 14:32
525 查看
先说说今天让我头疼了这么久的这个问题,简简单单的一个从相对路径读取plist文件,居然死活拿不到他的路径。
开始百度了一会,大多数都说,在Targets -> Build Phases -> Copy Bundle Resources里面没有导入资源文件,亦或是导入了,但是你删了,再重新导入,clean一下就OK了,有很多网友是这么解决了。
![](http://upload-images.jianshu.io/upload_images/1445324-83fedd2535538875.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
然后我试了N次,换用各种姿势导入,重新导入,重启Xcode,就差重启电脑了。后来想着,google一下吧。
看到两个关于这个问题stackOverflow里面的解决方案,也大同小异。硬着头皮一直往下看,看到了这么个回答:
![](http://upload-images.jianshu.io/upload_images/1445324-585e32c9b056090d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
就是不要在Release模式下面运行。我转念一想,我现在做的版本迭代,好像以前就是Release模式下的,瞬间如梦初醒。
有些时候,遇到的莫名的问题,其实很简单,但是没有前人趟过这个坑的话,打死我也不会想到是这个原因导致。困扰了大半天的问题就这么解决了,谨以此文,mark一下,也许会有和我一样惨的哥们呢?
开始百度了一会,大多数都说,在Targets -> Build Phases -> Copy Bundle Resources里面没有导入资源文件,亦或是导入了,但是你删了,再重新导入,clean一下就OK了,有很多网友是这么解决了。
![](http://upload-images.jianshu.io/upload_images/1445324-83fedd2535538875.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
然后我试了N次,换用各种姿势导入,重新导入,重启Xcode,就差重启电脑了。后来想着,google一下吧。
看到两个关于这个问题stackOverflow里面的解决方案,也大同小异。硬着头皮一直往下看,看到了这么个回答:
![](http://upload-images.jianshu.io/upload_images/1445324-585e32c9b056090d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
就是不要在Release模式下面运行。我转念一想,我现在做的版本迭代,好像以前就是Release模式下的,瞬间如梦初醒。
有些时候,遇到的莫名的问题,其实很简单,但是没有前人趟过这个坑的话,打死我也不会想到是这个原因导致。困扰了大半天的问题就这么解决了,谨以此文,mark一下,也许会有和我一样惨的哥们呢?
相关文章推荐
- iOS开发.[NSBundle mainBundle] 通过pathForResource返回路径为空.
- iOS开发中 [[NSBundle mainBundle] pathForResource: ofType:]路径为空的问题
- iOS问题笔记-[[NSBundle mainBundle] pathForResource: ofType:]方法获取不到资源路径
- iOS [[NSBundle mainBundle] pathForResource:@"" ofType:@""]无法获取到文件
- NSBundle mainBundle] pathForResource 返回nil的解决办法
- [NSBundle mainBundle] pathForResource: ofType: 获取不到数据
- 关于[[NSBundle mainBundle] pathForResource:@"name" ofType:@"type"]找不到指定文件的解决办法
- 关于[[NSBundle mainBundle] pathForResource:@"name" ofType:@"type"]找不到指定文件的解决办法
- 关于[[NSBundle mainBundle] pathForResource:@"name" ofType:@"type"]找不到指定文件的解决办法
- [[NSBundle mainBundle] pathForResource:@"name" ofType:@"type"] 找不到对应的文件解决方法
- [[NSBundle mainBundle]pathForResource..取值为空
- 关于[[NSBundle mainBundle] pathForResource:@"name"
- 关于[[NSBundle mainBundle] pathForResource:@"name" ofType:@"type"]找不到指定文件的解决办法
- [[NSBundle mainBundle]pathForResource:@"XXX" ofType:@"db"]为nil的解决办法
- 关于[[NSBundle mainBundle] pathForResource:@"name" ofType:@"type"]找不到指定文件的解决办法
- [[NSBundle mainBundle]pathForResource:@"name" ofType:@"type"] 获取不到本地文件
- [[NSBundle mainBundle]pathForResource..取值为空
- [NSBundle mainBundle] pathForResource: ofType: 获取不到数据
- ios pathForResource函数返回空值
- iOS开发-Could not find a storyboard named 'Main' in bundle NSBundle