您的位置:首页 > 其它

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: