ELCImagePicker 学习总结(二)
来源:互联网 发布:蓝牙4.0软件 编辑:程序博客网 时间:2024/05/16 17:30
- 头文件
#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 学习总结(七)
- ELCImagePicker 学习总结(八)
- oracle学习总结(二)
- oracle学习总结(二)
- oracle学习总结(二)
- oracle学习总结(二)
- 学习OpenGL总结二
- 雅思学习总结(二)
- oracle学习总结(二)
- gstreamer学习总结二
- 暑假学习总结二
- Python学习总结二
- ICSharpCode.SharpZipLib.Zip 使用
- RFID第三次作业第二题
- MySQL中的删除语句
- 获得某个月的天数(java,oracle,mysql)
- Java 虚拟机内存区域划分详解(1)
- ELCImagePicker 学习总结(二)
- 图标制作
- [转载]2015 前端[JS]工程师必知必会
- vim配置
- android基础学习之preferenceactivity
- Android上传文件至服务器
- 嵌入式系统 Boot Loader 技术内幕
- Ubuntu mongodb 安装和配置
- UGUI 之 制作角色受伤屏幕变红的动画提示(三)