UICollectionView數據源方法不調用問題


今天遇到一個關於UICollectionView的問題。

在xib中拖入UICollectionView,設置delegate和dataSource,都配置好了,但是發現,

部分數據源方法不被調用。

#pragma mark UICollectionView delegate and datasource

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {

    return 1;

}

 

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

    return 17;

}

 //以上兩個方法是被正常調用的

//但是cellForItemAtIndexPath方法不被調用

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

    static NSString *identifier = @"WHHostCollectionCell";

    WHHostCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; 

    return cell;

}

 - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

}

 

發現其他方法正常,只有cellForItemAtIndexPath不被調用。查找了好長時間,誤打誤撞,發現將代碼中的

layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;注釋掉就可以正常回調了。

至於原因,還不知為什么,按理該行代碼不應該影響方法的回調,所以還未確定問題,持續查找原因。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM