课程表

入门与环境搭建

简单控件的使用

视图控制

调用、存储、网络和动画

其他控件的使用

工具箱
速查手册

CollectionView数据源

当前位置:免费教程 » 移动开发 » CrossApp

类说明

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

示例:

  1. CACollectionViewCell* CollectionViewTest::collectionCellAtIndex(CACollectionView *collectionView,
  2. const CCSize& cellSize, unsigned int section, unsigned int row, unsigned int item)
  3. {
  4. CACollectionViewCell* p_Cell = collectionView->dequeueReusableCellWithIdentifier("CrossApp");
  5. if (p_Cell == NULL)
  6. {
  7. p_Cell = CACollectionViewCell::create("CrossApp");
  8. CAImageView* itemView = CAImageView::createWithImage(CAImage::create("logo.png"));
  9. itemView->setCenter(CCRect(cellSize.width*0.5,cellSize.height*0.5,cellSize.height * 0.90,cellSize.height * 0.90));
  10. itemView->setTag(99);
  11. p_Cell->addSubview(itemView);
  12. CALabel* itemText = CALabel::createWithCenter(CCRect(itemView->getBounds().size.width*0.5,
  13. itemView->getBounds().size.height*0.5,
  14. itemView->getBounds().size.width*0.6,
  15. itemView->getBounds().size.width*0.5));
  16. itemText->setTag(100);
  17. itemText->setFontSize(29 * CROSSAPP_ADPTATION_RATIO);
  18. itemText->setTextAlignment(CATextAlignmentCenter);
  19. itemText->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter);
  20. itemView->addSubview(itemText);
  21. }
  22. char pos[20] = "";
  23. sprintf(pos, "(%d,%d,%d)",section, row, item);
  24. CALabel* itemText = (CALabel*)p_Cell->getSubviewByTag(99)->getSubviewByTag(100);
  25. itemText->setText(pos);
  26. return p_Cell;
  27. }


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

转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号