关于UIUICollectionView

用xib加载时,需要注意的地方。

// 把UICollectionView注册近复用池里(千万不能忘)
[_collectionViewregisterClass:[DetailManageCellclass] forCellWithReuseIdentifier:cellIdentifier];
#pragma mark - UICollectionViewDataSource 代理方法 -
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    DetailManageCell *cell = [collectionViewdequeueReusableCellWithReuseIdentifier:cellIdentifierforIndexPath:indexPath];
    return cell;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 6;
}

#pragma mark - UICollectionViewDelegate 代理方法 -


#pragma mark - UICollectionViewLayout -
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    returnUIEdgeInsetsMake(0,20, 0, 20);
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    returnCGSizeMake(imageViewW,imageViewW);
}

UICollceionViewCell中加载xib(至于UICollectionView为什么要写这一方法加载,还不太清楚,只是不这样写,就没有显示)
- (instancetype)initWithFrame:(CGRect)frame{
    self = [superinitWithFrame:frame];
    if (self) {
        // 初始化时加载xib文件
        NSArray *arrayOfViews = [[NSBundlemainBundle]loadNibNamed:@"DetailManageCell"owner:self options:nil];
        // 如果路径不在,
        if (arrayOfViews.count <1) {
            returnnil;
        }
        // 如果xib中view不属于collectionView类,
        if (![[arrayOfViewsobjectAtIndex:0]isKindOfClass:[UICollectionViewCellclass]]) {
            returnnil;
        }
        // 加载xib
        self = [arrayOfViewsobjectAtIndex:0];
    }
    returnself;
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值