m_inum_of_cells=5;
TEMP temp;
for (int i = 0; i < m_inum_of_cells; i++)
{
temp.m_name = "zhangsa";
temp.m_score = "89.6";
temp.m_phone = "18966666666";
temp.m_phone2 = "1001";
m_temp.push_back(temp);
}
tableView = CCTableView::create(this, CCSizeMake(460, 400));
tableView->setDirection(kCCScrollViewDirectionVertical);
tableView->setPosition(ccp(40, 150));
tableView->setDelegate(this);
tableView->setVerticalFillOrder(kCCTableViewFillTopDown);
this->addChild(tableView);
tableView->reloadData();
CCTableViewCell* HelloWorld::tableCellAtIndex(CCTableView *table, unsigned int idx)
{
CCString *string = CCString::createWithFormat("%d", idx);
CCString *stringname = CCString::createWithFormat("%s", m_temp.m_name.c_str());
CCString *stringscore = CCString::createWithFormat("%s", m_temp.m_score.c_str());
CCString *stringphone = CCString::createWithFormat("%s", m_temp.m_phone.c_str());
CCString *stringphone2 = CCString::createWithFormat("%s", m_temp.m_phone2.c_str());
CCTableViewCell *cell = table->dequeueCell();
if (!cell) {
cell = new CustomTableViewCell();
cell->autorelease();
CCLabelTTF *label = CCLabelTTF::create(string->getCString(), "arial", 20.0);
label->setPosition(ccp(0, 0));
label->setAnchorPoint(CCPointZero);
label->setVisible(false);
cell->addChild(label);
CCLabelTTF *labelt = CCLabelTTF::create(UTEXT(stringname->getCString()), "arial", 20.0);
labelt->setPosition(ccp(90, 0));
labelt->setAnchorPoint(CCPointZero);
labelt->setTag(STUNAME);
cell->addChild(labelt);
CCLabelTTF *labelt1 = CCLabelTTF::create(stringscore->getCString(), "arial", 20.0);
labelt1->setPosition(ccp(220, 0));
labelt1->setAnchorPoint(CCPointZero);
labelt1->setTag(STUSCORE);
cell->addChild(labelt1);
CCLabelTTF *labelt2 = CCLabelTTF::create(stringphone->getCString(), "arial", 20.0);
labelt2->setPosition(ccp(300, 0));
labelt2->setAnchorPoint(CCPointZero);
labelt2->setTag(STUPHONE);
cell->addChild(labelt2);
CCLabelTTF *labelt3 = CCLabelTTF::create(stringphone2->getCString(), "arial", 20.0);
labelt3->setPosition(ccp(0, 0));
labelt3->setAnchorPoint(CCPointZero);
labelt3->setTag(STUPHONE2);
cell->addChild(labelt3);
}
else
{
/*CCLabelTTF *label = (CCLabelTTF*)cell->getChildByTag(123);
label->setString(string->getCString());*/
}
return cell;
vector 数组生成对应的项目 , 然后对一项 进行修改
想按照m_phone 或者 m_name 排序需要怎么实现啊