gpt4 book ai didi

objective-c - [UICollectionViewCell imageView] : unrecognized selector sent to instance

转载 作者:搜寻专家 更新时间:2023-10-30 19:52:27 25 4
gpt4 key购买 nike

我正在尝试使用 Collection View 并在其中显示静态图像,但出现以下错误:

[UICollectionViewCell imageView]: unrecognized selector sent to instance.

我已经配置了单元 identifire = Cell

这是我的代码:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

SSCollectionViewCell *cell = (SSCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

int imageNumber = indexPath.row % 10;

cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"Image%d.jpg",imageNumber]];

return cell;
}

这里是sscollectionViewCell.h代码

@interface SSCollectionViewCell : UICollectionViewCell

@property (weak) IBOutlet UIImageView *imageView;

@end

这里是SSColletionViewCell.m代码

#import "SSCollectionViewCell.h"
@interface SSCollectionViewCell ()

@end


@implementation SSCollectionViewCell
@synthesize imageView;

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
@end

谁能指出我哪里出错了?

最佳答案

改变

[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];

[self.collectionView registerClass:[SSCollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];

关于objective-c - [UICollectionViewCell imageView] : unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26795813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com