为什么我的子类不显示单元格?子类UICollectionViewCell不显示
我已经打过电话清醒从笔尖和initWithCoder
和initWithFrame
但没有任何属性都显示
@interface PhotoCollectionViewCell : UICollectionViewCell
@property (strong, nonatomic) IBOutlet UIImageView *photoImageView;
@end
,并在InterfaceBuilder中我.m文件
@implementation PhotoCollectionViewCell
-(void)awakeFromNib {
self.photoImageView.frame = self.bounds;
self.backgroundColor = [UIColor lightGrayColor];
}
-(id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
self.photoImageView.frame = self.bounds;
self.backgroundColor = [UIColor lightGrayColor];
}
return self;
}
我的细胞的类设置为PhotoCollectionViewCell
,并且在接口构建器中正确设置了重用标识符
@interface HomeViewController() {
NSMutableArray *photosArray;
}
@end
而且homeview.m
文件
-(void)viewDidLoad {
[self.collectionView registerClass:[PhotoCollectionViewCell class] forCellWithReuseIdentifier:@"photoCell"];
photosArray = [[NSMutableArray alloc] init];
UIImage *placeholder = [UIImage imageNamed:@"placeholder.png"];
[photosArray addObject:placeholder];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return photosArray.count;
}
- (PhotoCollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
PhotoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"photoCell" forIndexPath:indexPath];
cell.photoImageView.image = [photosArray objectAtIndex:indexPath.row];
return cell;
}
你不需要注册类或笔尖。这就是你在故事板中所做的。通过注册课程,您将覆盖故事板,并且您将获得您的手机,但没有连接任何插座。删除行'registerClass ...' – Fogmeister