Adr*_*lli 12 iphone nsarray nsrangeexception
我有一个包含10个项目的数组.当我IndexOfObject为元素编号9 调用" "时,元素编号10 Xcode返回异常:" NSRangeException"
原因:'_ [_ NSCFArray objectAtIndex:]索引:2147483647超出边界(10)'.
从前一个NSLog,我看到数组中存在两个元素,但indexOfObject没有找到它们.为什么?
我的代码是:
NSDictionary * headConfig =[avatarDictionaryToSave objectForKey:@"head_dictionary"];
NSString * headImage =[headConfig objectForKey:@"layer_key"];
NSString * pathFace =[[NSBundle mainBundle]pathForResource:@"Face" ofType:@"plist"];
NSLog(@"%@", headImage);
NSArray *arrayFace =[NSArray arrayWithContentsOfFile:pathFace];
NSLog(@"the elements are: %@", arrayFace);//here headImage is present
int index =[arrayFace indexOfObject:headImage];
NSLog(@"the index is %d", index);
Run Code Online (Sandbox Code Playgroud)
Nik*_*uhe 46
indexOfObject:NSNotFound当对象不在数组中时返回.NSNotFound定义为NSIntegerMax(在iOS 32位上== 2147483647).
因此,您正在寻找的对象似乎不存在.
| 归档时间: |
|
| 查看次数: |
11095 次 |
| 最近记录: |