我可以选择一个集合视图中的图像当我选择一个图像时,选择了错误的图像单元格一旦向下滚动出单元格视图,备份的细胞不再被选中,我怎样才能解决这个问题?滚动时单元格显示不正确
的ImageView的是在故事板定义。 资产都在照片库中。
这是PhotoCell.h文件。
#import <UIKit/UIKit.h>
#import <AssetsLibrary/AssetsLibrary.h>
@interface PhotoCell : UICollectionViewCell
@property(nonatomic,strong) ALAsset * asset;
@property (nonatomic,weak) IBOutlet UIImageView * PhotoImageView;
这是我的PhotoCell.m文件。
#import "PhotoCell.h"
@interface PhotoCell()
@end
@implementation PhotoCell
#pragma mark - User Made Method
- (void) setAsset:(ALAsset *)asset
{
// 2
_asset = asset;
self.PhotoImageView.image = [UIImage imageWithCGImage:[asset thumbnail]];
}
#pragma mark - CollectionView Cell Method
-(void)prepareForReuse
{
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
PhotoCell *cell =(PhotoCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"PhotoCell" forIndexPath:indexPath];
ALAsset * asset = self.assets[indexPath.row];
cell.asset = asset;
cell.backgroundColor = [UIColor redColor];
}
#pragma mark - Collection View Delegate
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
//NSLog(@"%@ - %d", NSStringFromSelector(_cmd), indexPath.item);
PhotoCell *cell = (PhotoCell *)[collectionView cellForItemAtIndexPath:indexPath];
chkboxBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[chkboxBtn setFrame:CGRectMake(60, 60, 30, 30)];
[chkboxBtn setTag:100];
[chkboxBtn setImage:[UIImage imageNamed:@"success.png"] forState:UIControlStateNormal];
[cell.contentView addSubview:chkboxBtn ];
}
-(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
// This removes the Check Box Button From the Cell After click it again
PhotoCell *cell =(PhotoCell *)[collectionView cellForItemAtIndexPath:indexPath];
[[cell.contentView viewWithTag:100] removeFromSuperview];
}
你可以在你的问题上花更多时间,并尝试更好地解释问题吗?否则,你不会得到任何吻... – tailec
它可能有可能,我需要花一些时间在我的问题,但PLZ试图理解。 –