UICollectionViewCell复用

来源:互联网 发布:手机qq电话录音软件 编辑:程序博客网 时间:2024/06/05 07:41

类似UITableView,cell的复用需要在代理方法中设置ReuseIdentifier,而UICollectionView设置复用的需要在  -(void)viewDidLoad中设置复用的代码

如果使用XIB创建的cell,复用代码

//  注册cell(告诉collectionView将来创建怎样的cell)    UINib *nib = [UINib nibWithNibName:@"MJProductCell" bundle:nil];    [self.collectionView registerNib:nib forCellWithReuseIdentifier:MJProductCellID];

如果是采用代码创建cell,复用代码

[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:MJProductCellID];


0 0