Skip to content

Commit

Permalink
修复空数组、默认显示index越界问题
Browse files Browse the repository at this point in the history
修复空数组、默认显示index越界问题
  • Loading branch information
wangziwu committed Dec 18, 2017
1 parent b79c6a1 commit 5002c7a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions ZWPhotoPreview/ZWPhotoPreview.m
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,24 @@ + (instancetype)zw_showPhotoPreview:(NSArray <ZWPhotoPreviewDataModel *>*)photoD
#pragma mark - layzing
-(void)setShowIndex:(NSInteger)showIndex{
_showIndex = showIndex;
[self changeIndexPageNum:showIndex];
[self handleRemarkInfo:showIndex];
[_mCollection scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:showIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionLeft animated:NO];
if (!self.photoDatas.count) {
return;
}
if (_showIndex>=self.photoDatas.count) {
_showIndex = self.photoDatas.count-1;
}
[self changeIndexPageNum:_showIndex];
[self handleRemarkInfo:_showIndex];
[_mCollection scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:_showIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionLeft animated:NO];
}
- (void)setPhotoDatas:(NSArray<ZWPhotoPreviewDataModel *> *)photoDatas {
_photoDatas = photoDatas;
[self changeIndexPageNum:0];
[self handleRemarkInfo:0];
if (photoDatas.count) {
[self changeIndexPageNum:0];
[self handleRemarkInfo:0];
}else{
[self removeFromSuperview];
}
}
- (UICollectionView *)mCollection{
if (!_mCollection) {
Expand Down
2 changes: 1 addition & 1 deletion ZWPreviewImageDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ - (IBAction)showImage{
}
ZWPhotoPreview *view = [ZWPhotoPreview zw_showPhotoPreview];
view.photoDatas = [ZWPhotoPreviewDataModel transformPhotoURLArray:mutArray];
view.showIndex = 3;
view.showIndex = 30;
}

- (void)didReceiveMemoryWarning {
Expand Down

0 comments on commit 5002c7a

Please sign in to comment.