JSRUN 用代码说话

CACollectionViewDataSource

编辑教程

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

JSRUN闪电教程系统是国内最先开创的教程维护系统, 所有工程师都可以参与共同维护的闪电教程,让知识的积累变得统一完整、自成体系。 大家可以一起参与进共编,让零散的知识点帮助更多的人。
X
支付宝
9.99
无法付款,请点击这里
金额: 0
备注:
转账时请填写正确的金额和备注信息,到账由人工处理,可能需要较长时间
如有疑问请联系QQ:565830900
正在生成二维码, 此过程可能需要15秒钟