爲什麼我的子類不顯示單元格?子類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