W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
類說明
CACollectionView的數(shù)據(jù)代理
CACollectionViewDataSource 方法(點(diǎn)擊查看方法介紹)
方法 | 說明 |
collectionCellAtIndex | 獲取指定cell |
collectionViewHeightForRowAtIndexPath | cell的高度 |
numberOfItemsInRowsInSection | 每個(gè)cell里的item數(shù)量 |
numberOfRowsInSection | 獲取對(duì)應(yīng)的section所包含的cell個(gè)數(shù) |
numberOfSections | 獲取tableview包含的section個(gè)數(shù) |
collectionViewSectionViewForHeaderInSection | headerView的內(nèi)容 |
collectionViewHeightForHeaderInSection | 每個(gè)section的headerView |
collectionViewSectionViewForFooterInSection | footerView的內(nèi)容 |
collectionViewHeightForFooterInSection | 每個(gè)section的footerView |
collectionViewWillDisplayCellAtIndex | 回調(diào)當(dāng)前將要顯示的Collection |
CACollectionViewDataSource 方法說明
virtual CACollectionViewCell* collectionCellAtIndex(CACollectionView *collectionView, const DSize& cellSize, unsigned int section, unsigned int row, unsigned int item)
返回值:virtual CACollectionViewCell*
參數(shù):
類型 | 參數(shù)名 | 說明 |
CACollectionView | collectionView | cell |
DSize | cellSize | cell大小 |
unsigned int | section | Section |
unsigned int | row | 行 |
unsigned int | item | 項(xiàng)目 |
解釋:獲取指定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
參數(shù):
類型 | 參數(shù)名 | 說明 |
CACollectionView | collectionView | cell |
unsigned int | section | Section |
unsigned int | row | 行 |
unsigned int | item | 項(xiàng)目 |
解釋:cell的高度
virtual unsigned int numberOfItemsInRowsInSection(CACollectionView *collectionView, unsigned int section, unsigned int row)
返回值:virtual unsigned int
參數(shù):
類型 | 參數(shù)名 | 說明 |
CACollectionView | collectionView | cell |
unsigned int | section | Section |
unsigned int | row | 行 |
unsigned int | item | 項(xiàng)目 |
解釋:每個(gè)cell里的item數(shù)量
virtual unsigned int numberOfRowsInSection(CACollectionView *collectionView, unsigned int section)
返回值:virtual unsigned int
參數(shù):
類型 | 參數(shù)名 | 說明 |
CACollectionView | collectionView | cell |
unsigned int | section | Section |
解釋:獲取對(duì)應(yīng)的section所包含的cell個(gè)數(shù)
virtual unsigned int numberOfSections(CACollectionView *collectionView)
返回值:virtual unsigned int
參數(shù):
類型 | 參數(shù)名 | 說明 |
CACollectionView | collectionView | cell |
解釋:獲取tableview包含的section個(gè)數(shù)
virtual CAView* collectionViewSectionViewForHeaderInSection(CACollectionView *collectionView, const DSize& viewSize, unsigned int section)
返回值:virtual CAView*
參數(shù):
類型 | 參數(shù)名 | 說明 |
CACollectionView | collectionView | cell |
DSize | cellSize | cell大小 |
unsigned int | section | Section |
解釋:headerView的內(nèi)容
virtual unsigned int collectionViewHeightForHeaderInSection(CACollectionView *collectionView, unsigned int section)
返回值:virtual unsigned int
參數(shù):
類型 | 參數(shù)名 | 說明 |
CACollectionView | collectionView | cell |
unsigned int | section | Section |
解釋:每個(gè)section的headerView
virtual CAView* collectionViewSectionViewForFooterInSection(CACollectionView *collectionView, const DSize& viewSize, unsigned int section)
返回值:virtual CAView*
參數(shù):
類型 | 參數(shù)名 | 說明 |
CACollectionView | collectionView | cell |
const DSize& | viewSize | 視圖大小 |
unsigned int | section | Section |
解釋:footerView的內(nèi)容
virtual unsigned int collectionViewHeightForFooterInSection(CACollectionView *collectionView, unsigned int section)
返回值:virtual unsigned int
參數(shù):
類型 | 參數(shù)名 | 說明 |
CACollectionView | collectionView | cell |
CCSize | cellSize | cell大小 |
unsigned int | section | Section |
解釋:每個(gè)section的footerView
virtual void collectionViewWillDisplayCellAtIndex(CACollectionView* table, CACollectionViewCell* cell, unsigned int section, unsigned int row, unsigned int item) {};
返回值:virtual void
參數(shù):
類型 | 參數(shù)名 | 說明 |
CACollectionView* | table | 表 |
CACollectionView | collectionView | cell |
unsigned int | section | Section |
unsigned int | row | 行 |
unsigned int | item | 項(xiàng)目 |
解釋:回調(diào)當(dāng)前將要顯示的Collection
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: