我正在使用自定義CollectionView單元實現自定義集合視圖。自定義CollectionViewCell屬性爲零
這是我的CollectionView實現。
- (void)setUpCollectionView{
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
[self.vwCarCollection setDataSource:self];
[self.vwCarCollection setDelegate:self];
[self.vwCarCollection registerClass:[FindMyCarCell class] forCellWithReuseIdentifier:@"FindMyCarCell"];
[self.vwCarCollection setBackgroundColor:[UIColor redColor]];
[self.vwCarCollection reloadData];
[self.vwCarCollection reloadInputViews];
}
我在「ViewDidLoad」上調用了這個函數。
這裏是我實施UICollectionViewDataSource
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
FindMyCarCell *cell = (FindMyCarCell *)[self.vwCarCollection dequeueReusableCellWithReuseIdentifier:@"FindMyCarCell" forIndexPath:indexPath];
cell.vwImgMain.image = [UIImage imageNamed:@"sample_car"];
cell.lblCarNo.text = @"GH2334343";
return cell;
}
當我調試我的代碼,細胞實例有這樣
<FindMyCarCell: 0x78645b30; baseClass = UICollectionViewCell; frame = (302 50; 221 180); layer = <CALayer: 0x786a07a0>>
但是,當我嘗試更新我的自定義單元格的ImageView的,它只是返回我的圖像視圖爲零。 我的實現出了什麼問題。有人可以建議我嗎?謝謝。
FindMyCarCell * cell =(FindMyCarCell *)[self.vwCarCollection dequeueReusableCellWithReuseIdentifier:@「FindMyCarCell」forIndexPath:indexPath];用collectionView代替self.vwCarCollection ..然後嘗試 – ajjjjjjjj
你可以顯示包含在FindMyCarCell中創建'vwImgMain'的方法嗎? – nynohu
有一個很好的教程聽到,但它很快,但概念類似於obj-c,只是通過這個http://randexdev.com/2014/08/uicollectionviewcell/ –