转自:
http://blog.csdn.net/playddt/article/details/8707703
http://blog.sina.com.cn/s/blog_4458fdda0101hvsb.html
(1)在CCTableView中点击空白区域依然会响应单元格事件,
在CCTableView.cpp中修改
改法是:
1.增加一个方法:(原有的方法的另一个bug是-cell_size~0的范围和0~cell_size算出来的index都是0)
int CCTableView::indexOfTouch(CCPoint offset){
const CCSize cellSize = m_pDataSource->cellSizeForTable(this);
if (m_eVordering == kCCTableViewFillTopDown) {
offset.y = this->getContainer()->getContentSize().height- offset.y - cellSize.height;
}
int index = 0;
float __index =0.0;
switch (this->getDirection()) {
case kCCScrollViewDirectionHorizontal:
__index = offset.x/cellSize.width;
if (__index<0) __index-=1;
index = __index;
break;
default:
__index = offset.y/cellSize.height;
if (__index<0) __index-=1;
index = __index;
break;
}
return index;
}
2. 修改
bool CCTableView::ccTouchBegan(CCTouch *pTouch,CCEvent *pEvent)
index = this->_indexFromOffset(point); 改为=> index = this->indexOfTouch(point);
(2)CCTableView problem with reloadData()
Create a Tableview, first loaded 0 data
numberOfCellsInTableView (CCTableView * table) {
CCLOG ("WarListLayer");
return arr-> count ();
}
When the network to return data, there are 10 data
I use tableView-> reloadData ();
tableview can not be displayed
When I drag the tableview, the tableview will be able to display.
--------------------------------------------------------------------------------------------------
try this when your data size is changed
CCPoint pos = tableView->getContainer()->getPosition();
tableView->getContainer()->setPosition( ccpAdd(pos,ccp(0,-CellHeight*numberOfAddedData)) );
tableView->reloadData();
-----------------------------------------------------------------------
//我是这么处理的,好象更好使一些吧!
if(m_pTableView)
{
m_pTableView->reloadData();
CCPoint pt = m_pTableView->minContainerOffset();
m_pTableView->setContentOffset(pt);
}
转载于:https://blog.51cto.com/ymbian/1209363