Quantcast
Channel: CSDN博客移动开发推荐文章
Viewing all articles
Browse latest Browse all 5930

UICollectionViewController的使用

$
0
0
@interface UICollectionViewController : UIViewController <UICollectionViewDelegate, UICollectionViewDataSource>

使用步骤

第一步:必须有布局

UICollectionViewFlowLayout *collectionViewLayout = [[UICollectionViewFlowLayout alloc]init];
    [collectionViewLayout setMinimumLineSpacing:10];//垂直间距
    [collectionViewLayout setMinimumInteritemSpacing:1];//水平间距
    [collectionViewLayout setItemSize:CGSizeMake(75, 75)];
    //设置分组内边距
    UIEdgeInsets insets = UIEdgeInsetsMake(10, 0, 0, 0);
    [collectionViewLayout setSectionInset:(insets)];
 self = [super initWithCollectionViewLayout:collectionViewLayout];

第二部:cell必须自己注册

// Register cell classes  for use in creating new collection view cells.
  // [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
   UINib *nib = [UINib nibWithNibName:@"HLProductCellCollectionViewCell" bundle:nil];
   [self.collectionView registerNib:nib forCellWithReuseIdentifier:reuseIdentifier];

错误分析:

如果没设置布局,即将报错:

1)'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter'
            [HLProductCollectionViewController alloc]initWithCollectionViewLayout:( UICollectionViewLayout*)
作者:u011018979 发表于2017/7/3 15:07:52 原文链接
阅读:70 评论:0 查看评论

Viewing all articles
Browse latest Browse all 5930

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>