我有一个 Collection View 。此 Collection View 的每个单元格都有一个标有标签 100 的 UIIMageView。
在某一时刻,显示单元格。用户选择一个单元格。我想在该单元格的 imageView 中复制该图像。
这是代码:
UICollectionViewCell *touchedCell = [self.collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
UIImageView *imageView = (UIImageView *)[touchedCell viewWithTag:100];
UIImage *image = imageView.image;
问题是此时,图像为零。 touchedCell
和 imageView
不为零。
为什么会这样?我如何获得该图像?
最佳答案
请遵循这些-- 首先创建一个实例变量
@implementation MyClass {
UIImage *newImage
}
然后 实现collectionview的这个委托(delegate)方法
-(void)collectionView:(UICollectionView *)collectionView
didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {
CustomCollectionViewCell *datasetCell =
(CustomCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
newImage = [UIImage imageWithCGImage:cell.customImageVIew.oldImage.CGImage];
}
因此,您的实例变量 newImage 将包含您所选单元格中图像的副本。 希望这有帮助
关于ios - 在 UICollectionViewCell 中获取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32347616/