我想在照片庫視圖中顯示照片庫中的所有圖片。我能夠通過assetsLibrary訪問所有圖像,但無法在表格中顯示它們。我沒有收到任何錯誤,但仍然不知道發生了什麼。從iphone照片庫中獲取照片並在表格視圖中顯示
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;
}
Pleaes幫助我在做什麼錯了....
感謝您的幫助