0

嗨,我是 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
4

3 回答 3

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];




}
于 2013-02-23T08:52:18.197 回答
2

[__NSArrayI objectAtIndex:]:索引 2147483648 超出范围 [0 .. 0]'

2147483648 是NSNotFound. 在您的代码中的某处,或者您正在使用的库的代码中,indexOfObject:正在一个数组上使用类似的东西,并且该索引被用于从另一个数组中获取一个值,但它失败了。

你的 for 循环看起来很可疑。您在每次迭代结束时为 photoController 分配一个值,这意味着只有您最后分配的值才会真正被使用。我不熟悉您使用的库,但您可能希望在将 MyPhoto 对象传递给单个 photoController 之前构建一个数组。

于 2013-02-23T08:53:15.113 回答
1

确保initWithImageURL: name:内部MyPhoto退货self。验证这一点NSLog(@"%@", [photo debugDescription]);

于 2013-02-23T07:56:45.133 回答