在我的 iPhone 应用程序中,我使用来自 github 的 FGallery 来显示照片库。我的问题有时是当我多次单击图库中的图像时(我认为主要是针对第一张图像),我的应用程序崩溃并显示以下错误消息。
* 由于未捕获的异常 'NSRangeException' 导致应用程序终止,原因:'* -[__NSArrayM objectAtIndex:]: index 4294967295 beyond bounds [0 .. 1]'
我将数组传递给 FGallery 类的代码在这里。
在.h
@interface ProdDetails : UIViewController<FGalleryViewControllerDelegate> {
NSMutableArray *networkImages;
FGalleryViewController *networkGallery;
}
@property(strong,nonatomic) NSMutableArray *networkImages;
@property(strong,nonatomic) FGalleryViewController *networkGallery;
-(void)setNetworkImages;
米
-(void)setNetworkImages {
self.networkImages = [[NSMutableArray alloc]init];
NSArray *data = [prodDet objectForKey:@"model_details"];
for (id eachDic in data) {
NSString *eachUrl = [NSString stringWithFormat:@"%@%@",IMG_INIT_URL,[eachDic objectForKey:@"model_imgurl"]];
eachUrl = [common replaceStringWhiteSpaceinUrl:eachUrl];
[self.networkImages addObject:eachUrl];
}
}
-(void)showProductImageGallery {
networkGallery = [[FGalleryViewController alloc]initWithPhotoSource:self];
CATransition *transition = [CATransition animation];
transition.duration = 1.0;
transition.type = kCATransitionFade;
transition.subtype = kCATransitionFromTop;
[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[self.navigationController pushViewController:networkGallery animated:NO];
}
任何人都请帮我解决这个问题。
编辑
谢谢大家。最后我发现了问题。问题出在FGallery中。
- (void)scrollingHasEnded {
_isScrolling = NO;
NSUInteger newIndex = fabs(floor( _scroller.contentOffset.x / _scroller.frame.size.width ));
//NSLog(@"%f,%f,%i",_scroller.contentOffset.x,_scroller.frame.size.width,newIndex);
// don't proceed if the user has been scrolling, but didn't really go anywhere.
if( newIndex == _currentIndex )
return;
// clear previous
[self unloadFullsizeImageWithIndex:_currentIndex];
_currentIndex = newIndex;
[self updateTitle];
[self updateButtons];
[self loadFullsizeImageWithIndex:_currentIndex];
[self preloadThumbnailImages];
}
当我们将第一张图片滚动到上一张时,_scroller.contentOffset.x 变为负数。所以floor( _scroller.contentOffset.x / _scroller.frame.size.width )
结果为负指数。我刚刚添加了 fabs 函数以产生正指数