我正在尝试从iphone(xcode 4.2)中的相册中获取所有图像/照片缩略图,遗憾的是我没有从中获取任何价值。我做了以下代码......
#import <UIKit/UIKit.h>
#import <AssetsLibrary/AssetsLibrary.h>
@interface MyImgPickerViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
{
IBOutlet UITableView *tableView;
IBOutlet UIActivityIndicatorView *activity;
NSMutableArray *assets;
}
@property(nonatomic,retain) IBOutlet UITableView *tableView;
@property(nonatomic,retain) IBOutlet UIActivityIndicatorView *activity;
@end
@implementation MyImgPickerViewController
@synthesize title,tableView,activity;
- (void)viewDidLoad
{
[super viewDidLoad];
[activity startAnimating];
//Define Blocks here;
assets =[[NSMutableArray alloc]init];
ALAssetsLibrary *library=[[ALAssetsLibrary alloc]init];
void (^assetEnumerator)( ALAsset *, NSUInteger , BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop)
{
if(result != NULL)
{
NSLog(@"See Asset: %@", result);
[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];
};
void(^ErrorBlock)(NSError*)=^(NSError *error)
{
NSLog(@"Failure");
};
[library enumerateGroupsWithTypes:ALAssetsGroupAlbum
usingBlock:assetGroupEnumerator
failureBlock: ErrorBlock
];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [assets count];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
//ALAsset *asset = [assets objectAtIndex:indexPath.row];
NSLog(@"......%@",assets);
[cell.imageView setImage:[UIImage imageWithCGImage:[[assets objectAtIndex:indexPath.row ]thumbnail]]];
[cell.textLabel setText:[NSString stringWithFormat:@"Photo %d", indexPath.row+1]];
return cell;
}
如果我正在运行此应用程序我没有获得任何资产,我找不到我错误的地方...... 有没有可用于ALAssetsLibrary的文档,除了类referance