1

在我的 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 函数以产生正指数

4

2 回答 2

0

错误描述说,it because you (or FGallery) trying to access object fromnetworkImages array from the index which is not exist (out of bound)!,使用此代码我们无法为您提供确切的帮助 ---因为它还不够!如果你找不到任何解决方案,FGallery你应该照顾MWPhotoBrowser。我发现它很容易使用。

于 2013-03-05T05:28:55.407 回答
0

使用这行代码

NSMutableArray *data = [prodDet objectForKey:@"model_details"];

代替

NSArray *data = [prodDet objectForKey:@"model_details"];
于 2013-03-05T07:17:35.410 回答