ELCImagePicker 学习总结(二)
2015-04-14 17:02
369 查看
头文件
#import <UIKit/UIKit.h>
#import <AssetsLibrary/AssetsLibrary.h>
@interface MyImagePickerViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
{
IBOutlet UITableView *tableView;
UIActivityIndicatorView *activity;
}
@property (nonatomic, retain) IBOutlet UITableView *tableView;
@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *activity;
@end
源文件
//
// MyImagePickerViewController.m
// MyImagePicker
//
// Created by lisa liu on 4/14/15.
// Copyright (c) 2015 lisa liu. All rights reserved.
//
#import "MyImagePickerViewController.h"
@interface MyImagePickerViewController ()
@property (nonatomic) NSMutableArray *assets;
@property (nonatomic, strong)ALAssetsLibrary* library;
@end
@implementation MyImagePickerViewController
@synthesize tableView;
@synthesize activity;
@synthesize assets;
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.activity startAnimating];
//Define Blocks Here
void (^assetEnumerator) (ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop){
if (result != nil) {
NSLog(@"See Asset:%@", result);
[self.assets addObject:result];
}
};
void (^assetGroupEnumerator) ( ALAssetsGroup *, BOOL *) = ^( ALAssetsGroup *group, BOOL *stop){
if (group != nil) {
[group enumerateAssetsUsingBlock:assetEnumerator];
}
[self.tableView reloadData];
[self.activity stopAnimating];
[self.activity setHidden:YES];
};
self.assets = [[NSMutableArray alloc]init];
ALAssetsLibrary *libraryL = [[ALAssetsLibrary alloc]init];
self.library = libraryL;
[self.library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock:^(NSError *error){
NSLog(@"A problem occured");
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [assets count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
ALAsset *asset = [assets objectAtIndex:indexPath.row];
[cell.imageView setImage:[UIImage imageWithCGImage:[asset thumbnail]]];
[cell.textLabel setText:[NSString stringWithFormat:@"Photo %d", indexPath.row + 1]];
return cell;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
#import <UIKit/UIKit.h>
#import <AssetsLibrary/AssetsLibrary.h>
@interface MyImagePickerViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
{
IBOutlet UITableView *tableView;
UIActivityIndicatorView *activity;
}
@property (nonatomic, retain) IBOutlet UITableView *tableView;
@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *activity;
@end
源文件
//
// MyImagePickerViewController.m
// MyImagePicker
//
// Created by lisa liu on 4/14/15.
// Copyright (c) 2015 lisa liu. All rights reserved.
//
#import "MyImagePickerViewController.h"
@interface MyImagePickerViewController ()
@property (nonatomic) NSMutableArray *assets;
@property (nonatomic, strong)ALAssetsLibrary* library;
@end
@implementation MyImagePickerViewController
@synthesize tableView;
@synthesize activity;
@synthesize assets;
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.activity startAnimating];
//Define Blocks Here
void (^assetEnumerator) (ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop){
if (result != nil) {
NSLog(@"See Asset:%@", result);
[self.assets addObject:result];
}
};
void (^assetGroupEnumerator) ( ALAssetsGroup *, BOOL *) = ^( ALAssetsGroup *group, BOOL *stop){
if (group != nil) {
[group enumerateAssetsUsingBlock:assetEnumerator];
}
[self.tableView reloadData];
[self.activity stopAnimating];
[self.activity setHidden:YES];
};
self.assets = [[NSMutableArray alloc]init];
ALAssetsLibrary *libraryL = [[ALAssetsLibrary alloc]init];
self.library = libraryL;
[self.library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock:^(NSError *error){
NSLog(@"A problem occured");
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [assets count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
ALAsset *asset = [assets objectAtIndex:indexPath.row];
[cell.imageView setImage:[UIImage imageWithCGImage:[asset thumbnail]]];
[cell.textLabel setText:[NSString stringWithFormat:@"Photo %d", indexPath.row + 1]];
return cell;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
相关文章推荐
- ELCImagePicker 学习总结(三)
- ELCImagePicker 学习总结(一)
- ELCImagePicker 学习总结(四)
- ELCImagePicker 学习总结(五)
- ELCImagePicker 学习总结(六)
- ELCImagePicker 学习总结(八)
- ELCImagePicker 学习总结(七)
- ELCImagePickerController 同时选择多张图片时,获取文件名称
- C# Image 学习总结
- Update: ELCImagePickerController
- [学习总结]9、Android-Universal-Image-Loader 图片异步加载类库的使用(超详细配置)
- react-native-image-crop-picker学习
- iOS开发利用ELCImagePicker第三方实现图片的多选
- 【IOS 开发学习总结-OC-67】Quartz 2D绘图(4-4)——图形变换+填充处理+core image 滤镜
- 小菜鸟的第一篇文章,在学习RN,就当是做笔记吧,iOS开发RN中添加第三方库react-native-image-picker
- [深度学习论文笔记][总结]Invariant gait feature extraction based on image transformation
- ELCImagePickerController 选择图片
- caffe学习之conver_imageset.bin的使用方法,caffe下图片转lmdb格式类型数据总结
- ELCImagePickerController
- ios 使用ELCImagePicker实现相册照片多选和真机拍照调试