我必须制作类似于iPhone中的照片应用的照片库。我已经包含了一个集合视图来显示图像。当我单击插入图像按钮时,将显示已保存的照片应用的相册(使用UIImagePicker
)。但我无法将图像加载回自定义collectionViewCell
。 CollectionViewCell
包含UIImageView
。
答案 0 :(得分:1)
对于collectionView,您cellForItemAtIndexPath
应如下所示。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
//create cel...
UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
//create UIImageView (declare imageView in header file)
self.cellImageView = [[UIImageView alloc] initWithFrame:"YOUR FRAME"];
//set image. delete this line if there's no before picking image in uipickercontroller
[self.cellImageView setImage:"YOUR IMAGE BEFORE USING IMAGEPICKER"];
[cell addSubView:self.cellImageView];
return cell;
}
您didFinishPickingMediaWithInfo
应该是这样的......
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
//set image when image is chosen from image picker controller
self.cellImageView = chosenImage;
//reload collectionView
[self.collectionView reloadData];
[picker dismissViewControllerAnimated:YES completion:NULL];
}
答案 1 :(得分:0)
请使用ALAsset库。
ALAsset对象表示由Photo应用程序管理的照片或视频。
请查看本教程系列“Creating An Image Gallery Like Over“。
在本教程中,您将学习如何在UICollectionView中实际显示已保存的相册。