Categories: CrossApp 教程

CACollectionViewDataSource

类说明

CACollectionView的数据代理

CACollectionViewDataSource 方法(点击查看方法介绍)

方法 说明
collectionCellAtIndex 获取指定cell
collectionViewHeightForRowAtIndexPath cell的高度
numberOfItemsInRowsInSection 每个cell里的item数量
numberOfRowsInSection 获取对应的section所包含的cell个数
numberOfSections 获取tableview包含的section个数
collectionViewSectionViewForHeaderInSection headerView的内容
collectionViewHeightForHeaderInSection 每个section的headerView
collectionViewSectionViewForFooterInSection footerView的内容
collectionViewHeightForFooterInSection 每个section的footerView
collectionViewWillDisplayCellAtIndex 回调当前将要显示的Collection

CACollectionViewDataSource 方法说明

virtual CACollectionViewCell* collectionCellAtIndex(CACollectionView *collectionView, const DSize& cellSize, unsigned int section, unsigned int row, unsigned int item)

返回值:virtual CACollectionViewCell*

参数:

类型 参数名 说明
CACollectionView collectionView cell
DSize cellSize cell大小
unsigned int section Section
unsigned int row
unsigned int item 项目

解释:获取指定cell

示例:

CACollectionViewCell* CollectionViewTest::collectionCellAtIndex(CACollectionView *collectionView, 
const CCSize& cellSize, unsigned int section, unsigned int row, unsigned int item)
{
    CACollectionViewCell* p_Cell = collectionView->dequeueReusableCellWithIdentifier("CrossApp");
    if (p_Cell == NULL)
    {
        p_Cell = CACollectionViewCell::create("CrossApp");
        CAImageView* itemView = CAImageView::createWithImage(CAImage::create("logo.png"));
        itemView->setCenter(CCRect(cellSize.width*0.5,cellSize.height*0.5,cellSize.height * 0.90,cellSize.height * 0.90));
        itemView->setTag(99);
        p_Cell->addSubview(itemView);
  
        CALabel* itemText = CALabel::createWithCenter(CCRect(itemView->getBounds().size.width*0.5, 
                                                            itemView->getBounds().size.height*0.5, 
                                                            itemView->getBounds().size.width*0.6, 
                                                            itemView->getBounds().size.width*0.5));
        itemText->setTag(100);
        itemText->setFontSize(29 * CROSSAPP_ADPTATION_RATIO);
        itemText->setTextAlignment(CATextAlignmentCenter);
        itemText->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter);
        itemView->addSubview(itemText);
  
    }
    char pos[20] = "";
    sprintf(pos, "(%d,%d,%d)",section, row, item);
    CALabel* itemText = (CALabel*)p_Cell->getSubviewByTag(99)->getSubviewByTag(100);
    itemText->setText(pos);
  
    return p_Cell;
}

virtual unsigned int collectionViewHeightForRowAtIndexPath(CACollectionView* collectionView, unsigned int section, unsigned int row)

返回值:virtual unsigned int

参数:

类型 参数名 说明
CACollectionView collectionView cell
unsigned int section Section
unsigned int row
unsigned int item 项目

解释:cell的高度

virtual unsigned int numberOfItemsInRowsInSection(CACollectionView *collectionView, unsigned int section, unsigned int row)

返回值:virtual unsigned int

参数:

类型 参数名 说明
CACollectionView collectionView cell
unsigned int section Section
unsigned int row
unsigned int item 项目

解释:每个cell里的item数量

virtual unsigned int numberOfRowsInSection(CACollectionView *collectionView, unsigned int section)

返回值:virtual unsigned int

参数:

类型 参数名 说明
CACollectionView collectionView cell
unsigned int section Section

解释:获取对应的section所包含的cell个数

virtual unsigned int numberOfSections(CACollectionView *collectionView)

返回值:virtual unsigned int

参数:

类型 参数名 说明
CACollectionView collectionView cell

解释:获取tableview包含的section个数

virtual CAView* collectionViewSectionViewForHeaderInSection(CACollectionView *collectionView, const DSize& viewSize, unsigned int section)

返回值:virtual CAView*

参数:

类型 参数名 说明
CACollectionView collectionView cell
DSize cellSize cell大小
unsigned int section Section

解释:headerView的内容

virtual unsigned int collectionViewHeightForHeaderInSection(CACollectionView *collectionView, unsigned int section)

返回值:virtual unsigned int 

参数:

类型 参数名 说明
CACollectionView collectionView cell
unsigned int section Section

解释:每个section的headerView

virtual CAView* collectionViewSectionViewForFooterInSection(CACollectionView *collectionView, const DSize& viewSize, unsigned int section)

返回值:virtual CAView*

参数:

类型 参数名 说明
CACollectionView collectionView cell
const DSize& viewSize 视图大小
unsigned int section Section

解释:footerView的内容

virtual unsigned int collectionViewHeightForFooterInSection(CACollectionView *collectionView, unsigned int section)

返回值:virtual unsigned int

参数:

类型 参数名 说明
CACollectionView collectionView cell
CCSize cellSize cell大小
unsigned int section Section

解释:每个section的footerView

virtual void collectionViewWillDisplayCellAtIndex(CACollectionView* table, CACollectionViewCell* cell, unsigned int section, unsigned int row, unsigned int item) {};

返回值:virtual void

参数:

类型 参数名 说明
CACollectionView* table
CACollectionView collectionView cell
unsigned int section Section
unsigned int row
unsigned int item 项目

解释:回调当前将要显示的Collection

冒牌SEO

前端开发者,欢迎大家一起沟通和交流。

Share
Published by
冒牌SEO

Recent Posts

自定义指令:聊聊vue中的自定义指令应用法则

今天我们来聊聊vue中的自定义…

5 天 ago

聊聊Vue中@click.stop和@click.prevent

一起来学下聊聊Vue中@cli…

2 周 ago

Nginx 基本操作:启动、停止、重启命令。

我们来学习Nginx基础操作:…

2 周 ago

Vue3:手动清理keep-alive组件缓存的方法

Vue3中手动清理keep-a…

3 周 ago

聊聊React和Vue组件更新的实现及区别

React 和 Vue 都是当…

3 周 ago