在 IOS 的集合视图中播种从 ELCImagePicker 中选择的多个图像
Posted
技术标签:
【中文标题】在 IOS 的集合视图中播种从 ELCImagePicker 中选择的多个图像【英文标题】:Sow Multiple Images Selected From ELCImagePicker In a Collection view in IOS 【发布时间】:2017-08-18 06:23:29 【问题描述】:我有一个视图控制器,我在其中添加了一个集合视图,当我传递静态图像数组时,它的显示效果很好,但我必须通过画廊选择或相机将图像传递给它,为此我在我的项目中使用了 ELCImagePicker选择多个图像,当我使用 elcimagepicker 从图库中选择多个图像时,它会选择图像,当我点击右上角的完成按钮时,它不会返回到视图控制器显示图像的位置,并且在集合视图中看不到图像.我的代码是,
- (IBAction)select:(id)sender
ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc]
initImagePicker];
elcPicker.maximumImagesCount = 4; //Set the maximum number of images to
select, defaults to 4
elcPicker.returnsOriginalImage = NO; //Only return the fullScreenImage, not
the fullResolutionImage
elcPicker.returnsImage = YES; //Return UIimage if YES. If NO, only return
asset location information
elcPicker.onOrder = YES; //For multiple image selection, display and return
selected order of images
elcPicker.imagePickerDelegate = self;
//Present modally
[self presentViewController:elcPicker animated:YES completion:nil];
- (void)elcImagePickerController:(ELCImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSArray *)info
if([info count] > 0)
for (NSDictionary *imageInfo in info)
UIImage *image = [imageInfo
valueForKey:UIImagePickerControllerOriginalImage];
NSLog(@"iii %@",image);
_arrImages=image;
NSLog(@"ppp %@",_arrImages);
//do anything here
[imagePicker dismissViewControllerAnimated:YES completion:nil];
- (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker
[self dismissViewControllerAnimated:YES completion:NULL];
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
return 1;
-(NSInteger) collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section
return [_arrImages count];
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
PatternCell *cell= [collectionView
dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
NSString *string=[_arrImages objectAtIndex:indexPath.row];
NSLog(@"IMAGE %@",string);
cell.img.image=[UIImage imageNamed:string];
cell.name.text=string;
return cell;
-(CGSize)collectionView:(UICollectionView *)collectionView layout:
(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath
*)indexPath
return CGSizeMake(150.0, 150.0);
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:
(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:
(NSInteger)section
return UIEdgeInsetsMake(5, 5, 5, 5);
谁能帮我解决我的错误? 它只显示这个屏幕, enter image description here
【问题讨论】:
你能帮我吗? @Jen Jose “当我点击右上角的完成按钮时,它不会返回到视图控制器显示图像的位置,并且在集合视图中看不到图像”当您关闭时会显示哪个屏幕ImagePicker 屏幕? 它显示了我的视图控制器,其中我有地方集合视图来显示图像。 @JenJose 关闭图像选择器后,您将数据分配给 arrImages=image;之后你需要重新加载collectionview。只需添加 [ collectionView reloadData]; 【参考方案1】:你需要将选中的图片传递给collectionview。
- (void)elcImagePickerController:(ELCImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSArray *)info
if([info count] > 0)
for (NSDictionary *imageInfo in info)
UIImage *image = [imageInfo
valueForKey:UIImagePickerControllerOriginalImage];
NSLog(@"iii %@",image);
_arrImages=image;
NSLog(@"ppp %@",_arrImages);
//Reload the collection view to display the selected images in cell.
[_collectionView reloadData];
[imagePicker dismissViewControllerAnimated:YES completion:nil];
【讨论】:
图像选择器没有关闭如何关闭它? @JenJose 这一行显示错误 [_collectionView reloadData];在 _collectionView 上。我已经为它做了出口,但它还显示错误。 @JenJose 它想用 UICollectionView 替换 collectionview。 @JenJose 我无法理解您的问题。请分享整个代码 给我你的邮件,我会给你发课程。 @JenJose以上是关于在 IOS 的集合视图中播种从 ELCImagePicker 中选择的多个图像的主要内容,如果未能解决你的问题,请参考以下文章