当前位置:K88软件开发文章中心编程语言APP编程CrossApp → 文章内容

CACollectionViewDataSource

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-23 13:52:02

由 ?﹏???ζ???﹏﹏? 创建, 最后一次修改 2016-09-07 类说明CACollectionView的数据代理CACollectionViewDataSource 方法(点击查看方法介绍)方法说明collectionCellAtIndex获取指定cellcollectionViewHeightForRowAtIndexPathcell的高度numberOfItemsInRowsInSection每个cell里的item数量numberOfRowsInSection获取对应的section所包含的cell个数numberOfSections获取tableview包含的section个数collectionViewSectionViewForHeaderInSectionheaderView的内容collectionViewHeightForHeaderInSection每个section的headerViewcollectionViewSectionViewForFooterInSectionfooterView的内容collectionViewHeightForFooterInSection每个section的footerViewcollectionViewWillDisplayCellAtIndex回调当前将要显示的CollectionCACollectionViewDataSource 方法说明virtual CACollectionViewCell* collectionCellAtIndex(CACollectionView *collectionView, const DSize& cellSize, unsigned int section, unsigned int row, unsigned int item)返回值:virtual CACollectionViewCell*参数:类型参数名说明CACollectionViewcollectionViewcellDSizecellSizecell大小unsigned intsectionSectionunsigned 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参数:类型参数名说明CACollectionViewcollectionViewcellunsigned intsectionSectionunsigned int row行unsigned intitem项目解释:cell的高度virtual unsigned int numberOfItemsInRowsInSection(CACollectionView *collectionView, unsigned int section, unsigned int row)返回值:virtual unsigned int参数:类型参数名说明CACollectionViewcollectionViewcellunsigned intsectionSectionunsigned int row行unsigned intitem项目解释:每个cell里的item数量virtual unsigned int numberOfRowsInSection(CACollectionView *collectionView, unsigned int section)返回值:virtual unsigned int参数:类型参数名说明CACollectionViewcollectionViewcellunsigned 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*参数:类型参数名说明CACollectionViewcollectionViewcellDSizecellSizecell大小unsigned intsectionSection解释:headerView的内容virtual unsigned int collectionViewHeightForHeaderInSection(CACollectionView *collectionView, unsigned int section)返回值:virtual unsigned int 参数:类型参数名说明CACollectionViewcollectionViewcellunsigned intsectionSection解释:每个section的headerViewvirtual CAView* collectionViewSectionViewForFooterInSection(CACollectionView *collectionView, const DSize& viewSize, unsigned int section)返回值:virtual CAView*参数:类型参数名说明CACollectionViewcollectionViewcellconst DSize&viewSize视图大小unsigned intsectionSection解释:footerView的内容virtual unsigned int collectionViewHeightForFooterInSection(CACollectionView *collectionView, unsigned int section)返回值:virtual unsigned int参数:类型参数名说明CACollectionViewcollectionViewcellCCSizecellSizecell大小unsigned intsectionSection解释:每个section的footerViewvirtual void collectionViewWillDisplayCellAtIndex(CACollectionView* table, CACollectionViewCell* cell, unsigned int section, unsigned int row, unsigned int item) {};返回值:virtual void参数:类型参数名说明CACollectionView*table表CACollectionViewcollectionViewcellunsigned intsectionSectionunsigned int row行unsigned intitem项目解释:回调当前将要显示的Collection

CACollectionViewDataSource