// // DKPhotoPickerGroupViewController.m // DKAssetsPickerDemo // Copyright (c) 2014年 com.zixue101.www. All rights reserved. // #define CELL_ROW 4 #define CELL_MARGIN 5 #define CELL_LINE_MARGIN 5 #import "DKPhotoPickerGroupViewController.h" #import "DKPhotoPickerCollectionView.h" #import "DKPhotoPickerDatas.h" #import "DKPhotoPickerGroupViewController.h" #import "DKPhotoPickerGroup.h" #import "DKPhotoPickerGroupTableViewCell.h" #import "DKPhotoPickerAssetsViewController.h" #import @interface DKPhotoPickerGroupViewController () @property (nonatomic , weak) DKPhotoPickerAssetsViewController *collectionVc; @property (nonatomic , weak) UITableView *tableView; @property (nonatomic , strong) NSArray *groups; @end @implementation DKPhotoPickerGroupViewController - (UITableView *)tableView{ if (!_tableView) { UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; tableView.translatesAutoresizingMaskIntoConstraints = NO; tableView.delegate = self; [self.view addSubview:tableView]; self.tableView = tableView; NSDictionary *views = NSDictionaryOfVariableBindings(tableView); NSString *heightVfl = @"V:|-0-[tableView]-0-|"; [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:heightVfl options:0 metrics:nil views:views]]; NSString *widthVfl = @"H:|-0-[tableView]-0-|"; [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:widthVfl options:0 metrics:nil views:views]]; } return _tableView; } - (void)viewDidLoad { [super viewDidLoad]; [self tableView]; // 设置按钮 [self setupButtons]; // 获取图片 [self getImgs]; self.title = @"选择相册"; } - (void) setupButtons{ UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithTitle:@"关闭" style:UIBarButtonItemStyleDone target:self action:@selector(back)]; self.navigationItem.rightBarButtonItem = barItem; } #pragma mark - - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.groups.count; } - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ DKPhotoPickerGroupTableViewCell *cell = [DKPhotoPickerGroupTableViewCell instanceCell]; cell.group = self.groups[indexPath.row]; return cell; } #pragma mark 跳转到控制器里面的内容 - (void) jump2StatusVc{ // 如果是相册 DKPhotoPickerGroup *gp = nil; for (DKPhotoPickerGroup *group in self.groups) { if ((self.status == PickerViewShowStatusCameraRoll || self.status == PickerViewShowStatusVideo) && ([group.groupName isEqualToString:@"Camera Roll"] || [group.groupName isEqualToString:@"相机胶卷"])) { gp = group; break; }else if (self.status == PickerViewShowStatusSavePhotos && ([group.groupName isEqualToString:@"Saved Photos"] || [group.groupName isEqualToString:@"保存相册"])){ gp = group; break; }else if (self.status == PickerViewShowStatusPhotoStream && ([group.groupName isEqualToString:@"Stream"] || [group.groupName isEqualToString:@"我的照片流"])){ gp = group; break; } } if (!gp) return ; DKPhotoPickerAssetsViewController *assetsVc = [[DKPhotoPickerAssetsViewController alloc] init]; assetsVc.cameraCount=self.cameraCount; assetsVc.selectPickerAssets = self.selectAsstes; assetsVc.assetsGroup = gp; assetsVc.groupVc = self; assetsVc.minCount = self.minCount; [self.navigationController pushViewController:assetsVc animated:NO]; } #pragma mark - - (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 80; } - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES]; DKPhotoPickerGroup *group = self.groups[indexPath.row]; DKPhotoPickerAssetsViewController *assetsVc = [[DKPhotoPickerAssetsViewController alloc] init]; assetsVc.cameraCount=self.cameraCount; assetsVc.selectPickerAssets = self.selectAsstes; assetsVc.groupVc = self; assetsVc.assetsGroup = group; assetsVc.minCount = self.minCount; [self.navigationController pushViewController:assetsVc animated:YES]; } #pragma mark - -(void)getImgs{ DKPhotoPickerDatas *datas = [DKPhotoPickerDatas defaultPicker]; __weak typeof(self) weakSelf = self; if (self.status == PickerViewShowStatusVideo){ // 获取所有的图片URLs [datas getAllGroupWithVideos:^(NSArray *groups) { self.groups = groups; if (self.status) { [self jump2StatusVc]; } weakSelf.tableView.dataSource = self; [weakSelf.tableView reloadData]; }]; }else{ // 获取所有的图片URLs [datas getAllGroupWithPhotos:^(NSArray *groups) { self.groups = groups; if (self.status) { [self jump2StatusVc]; } weakSelf.tableView.dataSource = self; [weakSelf.tableView reloadData]; }]; } } #pragma mark - - (void) back{ [self dismissViewControllerAnimated:YES completion:nil]; } @end