我正在尝试用自定义的collectionView类实现collectionViewCell。下面的代码工作正常,图像是从Collection视图类本身加载的。
customCollectionView.m
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
MyCell *cell = (MyCell *)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UIImage *Img = [UIImage imageNamed:[Images objectAtIndex:indexPath.row]];
cell.myImageView.image = Img;
cell.layer.borderWidth=2.0f;
cell.layer.borderColor=[UIColor lightGrayColor].CGColor;
return cell;
}MyCell.m
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}然而,当我将图像加载部分移动到自定义的CollectionViewCell类MyCell时,image没有显示。
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
UIImage *Img = [UIImage imageNamed:@"AppIcon.png"];
_myImageView.image = Img;
}
return self;
}我的目的是在特定的时间间隔内从MyCell类加载不同的图像,并在每个单元上显示。
发布于 2016-07-28 04:51:44
尝试在您的prepareForReuse MyCell中实现UICollectionViewCell的customCell方法
-(void)prepareForReuse {
_myImageView.image = [UIImage imageNamed:@"AppIcon.png"];
}尝试awakeFromNib并删除prepareForReuse
- (void)awakeFromNib {
_myImageView.image = [UIImage imageNamed:@"AppIcon.png"];
}https://stackoverflow.com/questions/38627272
复制相似问题