2015-09-06 43 views
1

爲什麼我的子類不顯示單元格?子類UICollectionViewCell不顯示

我已經打過電話清醒從筆尖initWithCoderinitWithFrame但沒有任何屬性都顯示

@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; 
} 

des

dfa

df

+0

你不需要註冊類或筆尖。這就是你在故事板中所做的。通過註冊課程,您將覆蓋故事板,並且您將獲得您的手機,但沒有連接任何插座。刪除行'registerClass ...' – Fogmeister

回答

1

您不需要註冊類或筆尖。這就是你在故事板中所做的。通過註冊課程,您將覆蓋故事板,並且您將獲得您的手機,但沒有連接任何插座。

刪除行...

[self.collectionView registerClass:[PhotoCollectionViewCell class] forCellWithReuseIdentifier:@"photoCell"]; 

,因爲你在故事板做你不需要它。

+0

美麗!謝謝。我其實已經閱讀了關於它的蘋果文檔,並沒有在那裏註釋。我會花幾個小時甚至沒有嘗試。不幸的是,我看過的所有教程都在他們的教程中,即使他們使用故事板。我猜想信任教程的失敗。謝謝 –

-1

在homeview.m要註冊的NIB不是類。

UINib *cellnib = [UINib nibWithNibName:PhotoCollectionViewCell bundle:nil]; 
[self.collectionView registerNib:cellnib forCellReuseIdentifier:@"photoCell"]; 
+0

我不使用筆尖,它不是一個表查看 –

相關問題