从图库中获取图像

从图库中获取图像

嗨,我可以从图库中获取图像,但是不会显示到收藏夹视图中。我已经编写了这样的代码

- (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;
}

请有人建议我该怎么做。非常感谢帮助。

最佳答案

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

关于ios - 如何从图库中获取图像到“查看单元格”集合?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28984748/

10-13 03:59