我想在表格视图中显示来自照片库的所有图片。我能够通过assetsLibrary访问所有图片,但无法在表格中显示它们。我没有收到任何错误信息,但仍然不知道发生了什么。
NSMutableArray *assets = [[NSMutableArray alloc]init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc]init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop){
if(group != NULL){
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop){
if(result != NULL){
[assets addObject:result];
}else NSLog(@"NO photo");;
}];
}
}
failureBlock:^(NSError *error){NSLog(@"Error");}];
表视图的数据源方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *identifier = @"id";
UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:identifier];
if(cell == NULL){
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
[cell.imageView setImage:[UIImage imageWithCGImage:[[assets objectAtIndex:indexPath.row]thumbnail]]];
[cell textLabel].text = @"Photo";
return cell;
请帮忙看一下我做错了什么......
感谢您的帮助。