void TableView::insertCellAtIndex(ssize_t idx) { if (idx == CC_INVALID_INDEX) { return; } long countOfItems = _dataSource->numberOfCellsInTableView(this); if (0 == countOfItems || idx > countOfItems-1) { return; } long newIdx = 0; auto cell = cellAtIndex(idx); if (cell) { newIdx = _cellsUsed.getIndex(cell); // Move all cells behind the inserted position for (long i = newIdx; i < _cellsUsed.size(); i++) { cell = _cellsUsed.at(i); this->_setIndexForCell(cell->getIdx()+1, cell); } } //insert a new cell cell = _dataSource->tableCellAtIndex(this, idx); this->_setIndexForCell(idx, cell); this->_addCellIfNecessary(cell); this->_updateCellPositions(); this->_updateContentSize(); }
void TableView::updateCellAtIndex(ssize_t idx) { if (idx == CC_INVALID_INDEX) { return; } long countOfItems = _dataSource->numberOfCellsInTableView(this); if (0 == countOfItems || idx > countOfItems-1) { return; } TableViewCell* cell = cellAtIndex(idx); if (cell) { _moveCellOutOfSight(cell); } cell = _dataSource->tableCellAtIndex(this, idx); if (cell) { _setIndexForCell(idx, cell); _addCellIfNecessary(cell); } }
CCTableViewCell * cellForTouch(CCTouch *t){ unsigned int index; CCPoint point = getContainer()->convertTouchToNodeSpace(t); index = _indexFromOffset(point); return cellAtIndex(index); }