有没有办法通过 xib 将 UICollectionViewCell 的子视图添加到 contentView?因为我认为这是正确的方法吗?我认为当我通过 xib 拖放 UI 时,它会被放入视图而不是 contentView
问问题
3255 次
2 回答
0
您可以执行类似于通过 nib 填充 TableViewCell 的操作。
创建一个笔尖
使用适当的唯一标签将子视图添加到其中
使用您创建的单元格注册 Collectionview
UINib *cellNib = [UINib nibWithNibName:@"ECVCell" bundle:[NSBundle mainBundle]]; [self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"ECVCell"];
使用
viewWithTag:
方法获取方法内添加视图的cellForItemAtIndexPath
实例
于 2013-02-08T05:26:49.357 回答
-1
当您将任何视图拖放到 UICollectionViewCell XIB 中时,您将拖动到 cell.contentView,而不是 cell.view。
请检查 didSelect,您将看到所有子视图
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
MyCell *cell = (MyCell*)[collectionView cellForItemAtIndexPath:indexPath];
NSArray *views = [cell.contentView subviews];
NSLog(@"Select %@",views);
}
于 2013-02-08T03:16:05.337 回答