我正在尝试将UICollectionViewCell从.xib加载到UICollectionView中,这也在.xib中的可重用UIView中。此UIView将加载到更多UIViewControllers。我发现,我需要像这样的测压元件:
[self.collectionView registerNib:[UINib nibWithNibName:@"MyCell" bundle:nil] forCellWithReuseIdentifier:@"CELL"];
但不会加载它。我在网上到处寻找答案,但我找不到这个具体的案例。
发布于 2015-10-05 18:58:10
有两种不同的情况,
1)如果您正在使用情节提要和自定义单元格。
2) UIViews和simple UIView( Nib的层次结构)。
你的似乎是第二种情况,首先你需要创建一个UICollectionView的实例(通过分配初始化方法)。然后使用以下方法注册持有您的单元格/视图的Nib。
[self.collectionView registerNib:[UINib nibWithNibName:CELL_IDENTIFIER bundle:nil] forCellWithReuseIdentifier:CELL_IDENTIFIER];
然后你可以使用下面的方法来使用那个笔尖
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell;
cell = (UICollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:CELL_IDENTIFIER
forIndexPath:indexPath];
//Populate your data here.
return cell;
}
希望这能帮上忙..:)
https://stackoverflow.com/questions/32946701
复制相似问题