問(wèn)題:
編譯執(zhí)行UICollectionView cellForItemAtIndexPath的 UICollectionViewDataSource 代理的方法,如下
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section;
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView;
但是不執(zhí)行
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;
說(shuō)明:
初始化成功并且設(shè)置代理有寫
<UICollectionViewDelegate,UICollectionViewDataSource>
collectionView.delegate = self;
collectionView.dataSource = self;
問(wèn)題原因:
設(shè)置Layout時(shí),直接使用UICollectionViewLayout.
UICollectionViewLayout *layout = [[UICollectionViewLayout alloc]init];
問(wèn)題解決:
不可直接使用 UICollectionViewLayout.因?yàn)閁ICollectionViewLayout是抽象類,必須要子類化才可以使用. 可以使用系統(tǒng)提供的UICollectionViewFlowLayout獲取(UICollectionViewLayout/UICollectionViewFlowLayout)的子類對(duì)象.