У меня есть изображения в виде коллекции, которые я могу выбрать. Когда я выбираю изображение, выбираются неправильные ячейки изображения. Как только я прокручиваю вниз из камеры, тогда резервное копирование ячейки больше не выбран. Как я могу решить эту проблему?Ячейки не отображаются должным образом при прокрутке
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 попытается понять. –