播下从ELCImagePicker中选择的多个图像在IOS的Collection视图中

时间:2017-08-18 06:23:29

标签: ios objective-c uicollectionview

我有一个视图控制器,我在其中添加了一个集合视图,当我传递静态图像数组时它显示正常但我必须通过图库选择或相机将图像传递给它我已经在我的项目中使用了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

1 个答案:

答案 0 :(得分:0)

您需要将所选图像传递给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];


}