自定义xib tableviewcell 无法通过nsdata dataWithContentsOfFile读取的问题
2014-12-22 14:59
288 查看
这几天通过xcode 5.1 开发一个自定义的xib tableviewcell,按理说,这种开发是小菜一碟的,然后悲剧就发生了。
cell =[[[NSBundle mainBundle] loadNibNamed:@"CooperationCheckItemCellTableViewCell" owner:self options:nil] objectAtIndex:0];
这一段代码出错,看了一下,这里的loadNibNamed是重写的,不是原来的方法,出错的位置在dataWithContentsOfFile 这个方法,可是看不出什么原因,
于是换了个写法。
NSData *nibData = [NSData dataWithContentsOfFile:localizedNibPath options: 0 error: &error];
if ([[NSFileManager defaultManager] isReadableFileAtPath: localizedNibPath] == YES)
NSLog (@"File is readable");
else
NSLog (@"File is read only");
if (nibData == nil)
{
NSLog(@"Failed to read file, error %@", error);
}
error来了,提示
Failed to read file, error Error Domain=NSCocoaErrorDomain Code=257 "The operation couldn’t be completed. (Cocoa error 257.)" UserInfo=0x17d53d80 {NSFilePath=/Users/huangymu/Library/Application Support/iPhone Simulator/6.1/Applications/2BACFF4C-2EBA-4268-A3B1-19792D260797/csmobile.app/CooperationCheckItemCellTableViewCell.nib,
NSUnderlyingError=0x17d53900 "The operation couldn’t be completed. 权限被拒绝"}
问题在于其他的xib可以被读取,就这个新写的xib不行,比较了一下其他地方tableview的delegate方法,基本都是一样的。怀疑问题出在xib本身,
比较了xib,发现有个选项不同
直觉告诉我可能是这里有问题,改称opensin 4.6
再次编译调试,ok了。所以可能用高版本开发,低版本环境跑存在问题。改低版本开发,就ok了
cell =[[[NSBundle mainBundle] loadNibNamed:@"CooperationCheckItemCellTableViewCell" owner:self options:nil] objectAtIndex:0];
这一段代码出错,看了一下,这里的loadNibNamed是重写的,不是原来的方法,出错的位置在dataWithContentsOfFile 这个方法,可是看不出什么原因,
于是换了个写法。
NSData *nibData = [NSData dataWithContentsOfFile:localizedNibPath options: 0 error: &error];
if ([[NSFileManager defaultManager] isReadableFileAtPath: localizedNibPath] == YES)
NSLog (@"File is readable");
else
NSLog (@"File is read only");
if (nibData == nil)
{
NSLog(@"Failed to read file, error %@", error);
}
error来了,提示
Failed to read file, error Error Domain=NSCocoaErrorDomain Code=257 "The operation couldn’t be completed. (Cocoa error 257.)" UserInfo=0x17d53d80 {NSFilePath=/Users/huangymu/Library/Application Support/iPhone Simulator/6.1/Applications/2BACFF4C-2EBA-4268-A3B1-19792D260797/csmobile.app/CooperationCheckItemCellTableViewCell.nib,
NSUnderlyingError=0x17d53900 "The operation couldn’t be completed. 权限被拒绝"}
问题在于其他的xib可以被读取,就这个新写的xib不行,比较了一下其他地方tableview的delegate方法,基本都是一样的。怀疑问题出在xib本身,
比较了xib,发现有个选项不同
直觉告诉我可能是这里有问题,改称opensin 4.6
再次编译调试,ok了。所以可能用高版本开发,低版本环境跑存在问题。改低版本开发,就ok了
相关文章推荐
- iOS: NSData的方法dataWithContentsOfFile:options:error:
- iOS: NSData的方法dataWithContentsOfFile:
- NSData dataWithContentsOfFile 返回值为nil
- 【原】[UIImage imageWithContentsOfFile:]引发的图片无法显示的问题
- nsdata dataWithContentsOfFile 大文件
- file_get_contents 无法读取https的问题解决!
- 小图用 imageNamed: 大图用 dataWithContentsOfFile:options
- imageNamed、imageWithContentsOfFile、imageWithData
- imageNamed和dataWithContentsOfFile的区别(1)
- UITableView获取cell的row值(解决自定义cell里的button通过点击无法获得cell的indexpath的问题)
- UITableView获取cell的row值(解决自定义cell里的button通过点击无法获得cell的indexpath的问题)
- 从相册读取大文件dataWithContentsOfURL?
- imageNamed/ imageWithContentsOfFile /imageWithData 的区别
- imageNamed/ imageWithContentsOfFile /imageWithData 的区别
- file_get_contents 无法读取https的问题解决!
- iOS: NSData的方法initWithContentsOfFile:
- NSData dataWithContentsOfURL
- UITableView获取cell的row值(解决自定义cell里的button通过点击无法获得cell的indexpath的问题
- imageNamed/ imageWithContentsOfFile /imageWithData 的区别
- 按字符串读取文件内容NSString stringWithContentsOfFile: (NSString类方法)