私の iPhone アプリでは、github の FGallery を使用してフォト ギャラリーを表示しています。私の問題は、ギャラリーの画像を複数回クリックすると (主に最初の画像だと思います)、次のエラー メッセージでアプリがクラッシュすることがあります。
* キャッチされていない例外 'NSRangeException' が原因でアプリを終了しています。
配列を 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関数を追加して、正のインデックスを生成しました