在我的iPhone應用程序中,我使用github上的FGallery顯示照片庫。 我的問題是有時當我多次點擊圖片庫中的圖片(我認爲它主要針對第一張圖片)時,我的應用程序崩潰並顯示以下錯誤消息。UIScrollView中的應用程序崩潰,索引超出範圍
*終止應用程序由於未捕獲的異常 'NSRangeException',原因: '* - [__ NSArrayM objectAtIndex:]:索引4294967295超出 範圍[0..1]'
我的代碼將數組傳遞給FGallery類就在這裏。
在.H
@interface ProdDetails : UIViewController<FGalleryViewControllerDelegate> {
NSMutableArray *networkImages;
FGalleryViewController *networkGallery;
}
@property(strong,nonatomic) NSMutableArray *networkImages;
@property(strong,nonatomic) FGalleryViewController *networkGallery;
-(void)setNetworkImages;
在.M
-(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)
結果爲負指數。 我只是說晶圓廠作用導致正折射率
檢查self.networkImages包含圖像的URL – NANNAV 2013-03-05 05:25:06
是的,它包含了圖像的URL。我可以滾動瀏覽正常的圖像。但是,當我快速滾動時,應用程序會變得漫長 – manujmv 2013-03-05 05:28:51