-
Notifications
You must be signed in to change notification settings - Fork 421
CATableViewDataSource
It’s CATableView’s data agent class, used to define data port of tableView.
Access modifier |
Method name |
Description |
public |
tableCellAtIndex |
obtain designated cell |
public |
numberOfRowsInSection |
Obtain cell number of corresponding section |
public |
numberOfSections |
Obtain section number of tableview |
public |
tableViewHeightForRowAtIndexPath |
obtain designated cell height
|
public |
tableViewHeightForHeaderInSection |
Obtain header view height of designated section |
public |
tableViewHeightForFooterInSection |
Obtain footer view height of designated section |
virtual CATableViewCell tableCellAtIndex(CATableView table, const CCSize& cellSize,unsigned int section, unsigned int row)**
Return value: CATableViewCell*
Parameter:
Type |
Parameter name |
Description |
CATableView* |
table |
current tableView |
const CCSize |
cellSize |
cell’s size |
unsigned int |
section |
cell’s subordinated section |
unsigned int |
row |
cell’s located line number |
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
CATableViewCell* TableViewTest::tableCellAtIndex(CATableView* table, const CCSize& cellSize, unsigned int section, unsigned int row) { CATableViewCell* cell = table->dequeueReusableCellWithIdentifier("CrossApp"); if (cell == NULL) { cell = CATableViewCell::create("CrossApp"); CALabel* cellText = CALabel::createWithCenter(CCRect(cellSize.width*0.1, cellSize.height*0.5, cellSize.width*0.3, cellSize.height*0.8)); cellText->setTag(100); cellText->setFontSize(30 * CROSSAPP_ADPTATION_RATIO); cellText->setColor(CAColor_blueStyle); cellText->setTextAlignment(CATextAlignmentCenter); cellText->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); cell->addSubview(cellText);
CAButton* cellBtn = CAButton::createWithCenter(CCRect(cellSize.width*0.8,cellSize.height*0.5,cellSize.width*0.2,cellSize.height*0.5),CAButtonTypeRoundedRect); cellBtn->setTag(102); cellBtn->setTitleForState(CAControlStateAll,"Touch"); cellBtn->addTarget(this, CAControl_selector(TableViewTest::cellBtnCallback), CAControlEventTouchUpInSide); cell->addSubview(cellBtn); } char order[20] = ""; sprintf(order, "cell-%d", row); CALabel* cellText = (CALabel*)cell->getSubviewByTag(100); cellText->setText(order);
return cell;
} |
Generally cell’s displayed data will change, but the screen of cell itself won’t. So based on actual conditions, we usually customize screen and won’t fix cell’s displayed data when creating new cell.
virtual unsigned int numberOfRowsInSection(CATableView *table, unsigned int section)
Return value: unsigned int
Parameter:
Type |
Parameter name |
Description |
CATableView* |
table |
current tableView |
unsigned int |
section |
cell’s subordinated section |
virtual unsigned int numberOfSections(CATableView *table)
Return value: unsigned int
Parameter:
Type |
Parameter name |
Description |
CATableView* |
table |
current tableView |
virtual unsigned int tableViewHeightForRowAtIndexPath(CATableView table, unsigned int section, unsigned int row)*
Return value: unsigned int
Parameter:
Type |
Parameter name |
Description |
CATableView* |
table |
current tableView |
unsigned int |
section |
cell’s subordinated section |
unsigned int |
row |
cell’s located line number |
virtual unsigned int tableViewHeightForHeaderInSection(CATableView table, unsigned int section)*
Return value: unsigned int
Parameter:
Type |
Parameter name |
Description |
CATableView* |
table |
current tableView |
unsigned int |
section |
cell’s subordinated section |
virtual unsigned int tableViewHeightForFooterInSection(CATableView table, unsigned int section)*
Return value: unsigned int
Parameter:
Type |
Parameter name |
Description |
CATableView* |
table |
current tableView |
unsigned int |
section |
cell’s subordinated section |