嗨,我是iphone编程的新手,我正在使用EGOPhotViewer并希望使用此代码显示图像,
for ( recipeImages in recipeImages.imgArray) {
photo = [[MyPhoto alloc] initWithImageURL:[NSURL URLWithString:recipeImages.recipie_img_url]name:recipeImages.recipe_name];
NSLog(@"%@",recipeImages.recipie_img_url);
MyPhotoSource *source = [[MyPhotoSource alloc] initWithPhotos:[NSArray arrayWithObjects:photo ,nil]];
photoController = [[EGOPhotoViewController alloc] initWithPhotoSource:source];
}
[APPDELEGATE.navigationController pushViewController:photoController animated:YES];
我收到此错误
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 2147483648 beyond bounds [0 .. 0]'
*** First throw call stack:
(0x225f012 0x2084e7e 0x2214b44 0x9e1e4 0xa46c4 0x1b45dc9 0x22b90c5 0x2213efa 0x1a7a482 0x1a8d73b 0xa9d7c 0xa6a4e 0xa5081 0xa0499 0x10af753 0x10afa7b 0x10bd590 0x10c55bd 0x10c5eab 0x10c64a3 0x10c6098 0x5bad6 0x2098705 0xfcf920 0xfcf8b8 0x1090671 0x1090bcf 0x108fd38 0xfff33f 0xfff552 0xfdd3aa 0xfcecf8 0x2c15df9 0x2c15ad0 0x21d4bf5 0x21d4962 0x2205bb6 0x2204f44 0x2204e1b 0x2c147e3 0x2c14668 0xfcc65c 0x263a 0x2545)
libc++abi.dylib: terminate called throwing an exception
答案 0 :(得分:2)
我通过编写此代码解决了这个问题
NSMutableArray *localImagesArray = [[NSMutableArray alloc] init];
for ( recipeImages in recipeImages.imgArray) {
photo = [[MyPhoto alloc] initWithImageURL:[NSURL URLWithString:recipeImages.recipie_img_url]name:recipeImages.recipe_name];
NSLog(@"%@",recipeImages.recipie_img_url);
NSLog(@"%@", [photo debugDescription]);
[localImagesArray addObject:photo];
}
MyPhotoSource *source = [[MyPhotoSource alloc] initWithPhotos:localImagesArray];
photoController = [[EGOPhotoViewController alloc] initWithPhotoSource:source];
[APPDELEGATE.navigationController pushViewController:photoController animated:YES];
}
答案 1 :(得分:2)
[__ NSArrayI objectAtIndex:]:索引2147483648超出界限[0 .. 0]'
2147483648是NSNotFound
。在代码中的某个地方,或者您正在使用的库的代码,类似于indexOfObject:
的东西正在一个数组上使用,并且该索引用于从另一个数组中获取值,并且它正在失败。
你的for循环看起来非常可疑。您在每次迭代结束时为photoController分配一个值,这意味着只有您最后分配的值才会被实际使用。我不熟悉您正在使用的库,但您可能希望在将它们传递给单个photoController之前构建一组MyPhoto对象。
答案 2 :(得分:1)
确保initWithImageURL: name:
内的MyPhoto
返回self
。
使用NSLog(@"%@", [photo debugDescription]);