Let the default selected album to be CameraRoll.

Fixing index from NSInteger* to NSInteger.

https://github.com/DmcSDK/cordova-plugin-mediaPicker/issues/50
https://github.com/DmcSDK/cordova-plugin-mediaPicker/issues/36
This commit is contained in:
Roger Guo
2018-11-13 08:50:19 +08:00
parent 8172f8194f
commit 546f98dfd1
3 changed files with 24 additions and 19 deletions
+3 -3
View File
@@ -20,12 +20,12 @@
/**
select index
*/
@property (nonatomic ,assign)NSInteger* nowIndex;
@property (nonatomic ,assign)NSInteger nowIndex;
/**
选择相册之后、传递相册数据源
*/
@property (nonatomic ,copy)void(^didSelectAlbumBlock)(NSInteger *index);
@property (nonatomic ,copy)void(^didSelectAlbumBlock)(NSInteger index);
-(void)setListDataSource:(NSMutableArray *)dataSource dataNameSource:(NSMutableArray *)names nowSelectAlbum:(NSInteger*)nowIndex ;
-(void)setListDataSource:(NSMutableArray *)dataSource dataNameSource:(NSMutableArray *)names nowSelectAlbum:(NSInteger)nowIndex ;
@end
+6 -6
View File
@@ -42,18 +42,18 @@
#pragma mark - setter
-(void)setListDataSource:(NSMutableArray *)dataSource dataNameSource:(NSMutableArray *)names nowSelectAlbum:(NSInteger*)nowIndex
-(void)setListDataSource:(NSMutableArray *)dataSource dataNameSource:(NSMutableArray *)names nowSelectAlbum: (NSInteger)nowIndex
{
_dataSource=dataSource;
_dataNameSource=names;
_nowIndex=nowIndex;
[self.tableView reloadData];
int scrolltoIndex=0;
NSInteger scrolltoIndex = 0;
//下面代码是让下拉选中了有个居中的感觉
if((int)_nowIndex>[_dataNameSource count]-4){
scrolltoIndex= [_dataNameSource count]-1;
if(_nowIndex > [_dataNameSource count]-4){
scrolltoIndex = [_dataNameSource count]-1;
}else{
scrolltoIndex=((int)_nowIndex+3);
scrolltoIndex=(_nowIndex+3);
}
if([_dataNameSource count]>3){
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForItem:scrolltoIndex inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
@@ -150,4 +150,4 @@
}
@end
@end
@@ -18,7 +18,7 @@
AlbumListView *albumlistView;
NSMutableArray *albumsTitlelist;
NSMutableArray * dataSource;
NSInteger* nowSelectAlbum;
NSInteger nowSelectAlbum;
}
@property (strong, nonatomic) PHImageManager *manager;
@@ -104,7 +104,7 @@
[albumlistView setListDataSource:dataSource dataNameSource:albumsTitlelist nowSelectAlbum:nowSelectAlbum];
__weak DmcPickerViewController* weakSelf = self;
//设置选择相册之后的block回调
[albumlistView setDidSelectAlbumBlock:^(NSInteger *index) {
[albumlistView setDidSelectAlbumBlock:^(NSInteger index) {
[weakSelf show:index];
@@ -203,7 +203,9 @@
}else if(self.selectMode==102){
options.predicate = [NSPredicate predicateWithFormat:@"mediaType == %ld", PHAssetMediaTypeVideo];
}
int defaultSelection = 0;
int i = 0;
for (PHFetchResult *fetchResult in allAlbums) {
for (PHAssetCollection *collection in fetchResult) {
// 有可能是PHCollectionList类的的对象,过滤掉
@@ -212,23 +214,26 @@
if (collection.estimatedAssetCount <= 0) continue;
if (collection.assetCollectionSubtype == PHAssetCollectionSubtypeSmartAlbumAllHidden) continue; //包含隐藏照片或视频的文件夹
if (collection.assetCollectionSubtype == 1000000201) continue; //『最近删除』相册
if (collection.assetCollectionSubtype == PHAssetCollectionSubtypeSmartAlbumUserLibrary) {
defaultSelection = i;
}
PHFetchResult *group = [PHAsset fetchAssetsInAssetCollection:collection options:options];
if([group count]>0){
[albumsTitlelist addObject:collection.localizedTitle];
[dataSource addObject:group];
i++;
}
}
}
}
_manager = [PHImageManager defaultManager];
[self show:0];
[self show: defaultSelection];
}
-(void)show:(NSInteger *)index{
-(void)show:(NSInteger) index {
if([dataSource count]>0){
fetchResult = dataSource[(int)index];
[self setTitleView:albumsTitlelist[(int)index]];
fetchResult = dataSource[index];
[self setTitleView:albumsTitlelist[index]];
[_collectionView reloadData];
[self hiddenAlbumlistView];
[_collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0] atScrollPosition:UICollectionViewScrollPositionTop animated:NO];