我想在表格视图中显示照片库中的所有图像.我可以通过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;
}
请求帮助我做错了….
感谢帮助