類說明
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
更多建議: