OStack程序员社区-中国程序员成长平台

标题: ios - 如何从图库中获取图像以收集查看单元格? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 05:46
标题: ios - 如何从图库中获取图像以收集查看单元格?

您好,我可以从图库中获取图像,但不会显示到 Collection View 中。我已经编写了这样的代码

- (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)galleryClickedid)sender
{

NSLog(@"GalleryClicked");

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

}

-(void)imagePickerControllerUIImagePickerController *)picker didFinishPickingMediaWithInfoNSDictionary *)info

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

- (MyCell *)collectionViewUICollectionView *)collectionView cellForItemAtIndexPathNSIndexPath *)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;
}

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



Best Answer-推荐答案


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

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






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4