iOS CollectionView加载xib CollectionViewCell

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-23 06:34   136   0

static NSString *identifier=@"cell";


- (void)viewDidLoad {

[super viewDidLoad];

self.automaticallyAdjustsScrollViewInsets=NO;//去掉顶部留白

//注册cell 有几种cell样式注册几次

[_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:identifier];

}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

//在这里注册自定义的XIBcell否则会提示找不到标示符指定的cell

UINib *nib = [UINibnibWithNibName:@"FCollectionViewCell"bundle: [NSBundlemainBundle]];

[collectionView registerNib:nib forCellWithReuseIdentifier:identifier];

FCollectionViewCell *cell = [collectionViewdequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

return cell;

}

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP