codecamp

CACollectionViewDataSource

类说明

CACollectionView的数据代理


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

方法说明
collectionCellAtIndex获取指定cell
collectionViewHeightForRowAtIndexPathcell的高度
numberOfItemsInRowsInSection每个cell里的item数量
numberOfRowsInSection获取对应的section所包含的cell个数
numberOfSections获取tableview包含的section个数
collectionViewSectionViewForHeaderInSectionheaderView的内容
collectionViewHeightForHeaderInSection每个section的headerView
collectionViewSectionViewForFooterInSectionfooterView的内容
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*

参数:

类型参数名说明
CACollectionViewcollectionViewcell
DSizecellSizecell大小
unsigned intsectionSection
unsigned int row
unsigned intitem项目

解释:获取指定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

参数:

类型参数名说明
CACollectionViewcollectionViewcell
unsigned intsectionSection
unsigned int row
unsigned intitem项目

解释:cell的高度


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

返回值:virtual unsigned int

参数:

类型参数名说明
CACollectionViewcollectionViewcell
unsigned intsectionSection
unsigned int row
unsigned intitem项目

解释:每个cell里的item数量


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

返回值:virtual unsigned int

参数:

类型参数名说明
CACollectionViewcollectionViewcell
unsigned intsectionSection

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


virtual unsigned int numberOfSections(CACollectionView *collectionView)

返回值:virtual unsigned int

参数:

类型参数名说明
CACollectionViewcollectionViewcell

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


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

返回值:virtual CAView*

参数:

类型参数名说明
CACollectionViewcollectionViewcell
DSizecellSizecell大小
unsigned intsectionSection

解释:headerView的内容


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

返回值:virtual unsigned int 

参数:

类型参数名说明
CACollectionViewcollectionViewcell
unsigned intsectionSection

解释:每个section的headerView


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

返回值:virtual CAView*

参数:

类型参数名说明
CACollectionViewcollectionViewcell
const DSize&viewSize视图大小
unsigned intsectionSection

解释:footerView的内容


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

返回值:virtual unsigned int

参数:

类型参数名说明
CACollectionViewcollectionViewcell
CCSizecellSizecell大小
unsigned intsectionSection

解释:每个section的footerView


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

返回值:virtual void

参数:

类型参数名说明
CACollectionView*table
CACollectionViewcollectionViewcell
unsigned intsectionSection
unsigned int row
unsigned intitem项目

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


CACollectionView(容器)
CASlider(滑动条)
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

四、调用系统支持

八、宏定义

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }