类说明
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