这几天通过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了