如何从图库中获取图像到uicollectionView单元格?

时间:2015-03-11 10:56:12

标签: ios

嗨我可以从图库中获取图像但是没有显示到集合视图中。我已经编写了这样的代码

- (void)viewDidLoad
{

picker=[[UIImagePickerController alloc]init];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.collectionView registerNib:[UINib nibWithNibName:@"MyCell" bundle:nil] forCellWithReuseIdentifier:@"CELL"];

}
- (IBAction)galleryClicked:(id)sender
{

NSLog(@"GalleryClicked");

picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[picker setAllowsEditing:YES];
[self presentViewController:picker animated:YES completion:nil];

}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{
inputImage= info[UIImagePickerControllerEditedImage];
NSLog(@"inputImage is :%@",inputImage);
[picker dismissViewControllerAnimated:YES completion:nil];
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 100;
}

- (MyCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CELL" forIndexPath:indexPath];   
UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:100];
UILabel *descLabel = (UILabel *)[cell viewWithTag:110];
self.recipeImageView.image = inputImage;    
return cell;
}

请有人建议我如何做到这一点。非常感谢帮助。

1 个答案:

答案 0 :(得分:1)

您需要将self.recipeImageView.image = inputImage;更改为recipeImageView.image = inputImage;