CCTableViewCell* ItemListScene::tableCellAtIndex(CCTableView *table, unsigned int idx) { CCTableViewCell *cell = table->dequeueCell(); CCLabelTTF *itemNumberLabel = NULL; CCLabelTTF *itemNameLabel = NULL; if (!cell) { cell = new CCTableViewCell(); cell->autorelease(); itemNumberLabel = CCLabelTTF::create("", DefaultFontName, FontSizeNormal); itemNumberLabel->setAnchorPoint(ccp(0.0, 0.5)); itemNumberLabel->setPosition(ccp(kItemNumberLabelMarginLeft, kItemCellHeight / 2)); itemNumberLabel->setTag(kItemCellTagNumberLabel); cell->addChild(itemNumberLabel); itemNameLabel = CCLabelTTF::create("", DefaultFontName, FontSizeNormal); itemNameLabel->setAnchorPoint(ccp(0.0, 0.5)); itemNameLabel->setPosition(ccp(kItemNameLabelMarginLeft, kItemCellHeight / 2)); itemNameLabel->setTag(kItemCellTagNameLabel); cell->addChild(itemNameLabel); } Item item = selectedItem(idx); cell->removeChildByTag(kItemCellTagImage); itemNumberLabel = (CCLabelTTF *)cell->getChildByTag(kItemCellTagNumberLabel); itemNumberLabel->setString(CCString::createWithFormat("%02lld", item.get_id())->getCString()); CCSprite *itemImage = NULL; itemNameLabel = (CCLabelTTF *)cell->getChildByTag(kItemCellTagNameLabel); if (item->count > 0) { itemImage = CCSprite::createWithSpriteFrameName(item->image.c_str()); itemNameLabel->setString(item->name.c_str()); } else { itemImage = CCSprite::createWithSpriteFrameName(NotFoundItemImage); itemNameLabel->setString(MessageNotFoundItemNameText); } itemImage->setAnchorPoint(ccp(0.0, 0.5)); itemImage->setPosition(ccp(kItemImageMarginLeft, kItemCellHeight / 2)); itemImage->setTag(kItemCellTagImage); cell->addChild(itemImage); return cell; }
CCTableViewCell* MyScrollView::tableCellAtIndex(CCTableView *table, unsigned int idx) { CCLOG("idx = %d", idx); CCTableViewCell *cell = table->dequeueCell(); CCSprite *sprite; switch(idx) { case 0: sprite = CCSprite::create("bangzhuguanyu/1.png"); break; case 1: sprite = CCSprite::create("bangzhuguanyu/2.png"); break; case 2: sprite = CCSprite::create("bangzhuguanyu/3.png"); break; case 3: sprite = CCSprite::create("bangzhuguanyu/4.png"); break; case 4: sprite = CCSprite::create("bangzhuguanyu/5.png"); break; case 5: sprite = CCSprite::create("bangzhuguanyu/6.png"); break; case 6: sprite = CCSprite::create("bangzhuguanyu/7.png"); break; default: break; } if (!cell) { cell = new CCTableViewCell(); cell->autorelease(); sprite->setAnchorPoint(CCPointZero); sprite->setPosition(ccp(0, 0)); sprite->setTag(123); cell->addChild(sprite); } else { cell->removeChildByTag(123); sprite->setAnchorPoint(CCPointZero); sprite->setPosition(ccp(0, 0)); sprite->setTag(123); cell->addChild(sprite); } return cell; }
CCTableViewCell* MallMarkets::tableCellAtIndex(cocos2d::extension::CCTableView *table, unsigned int idx) { //CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCSize tableCellSize = CCSizeMake(1136, 100); CCTableViewCell *pCell = table->dequeueCell(); string temp = this->coinImageName[idx]; string imagePath = writablePathLocal+temp; CCSprite *prizePicture = CCSprite::create(imagePath.c_str()); prizePicture->setAnchorPoint(CCPointZero); prizePicture->setPosition(ccp(20, 60)); prizePicture->setScale(1); prizePicture->setTag(122); //pCell->addChild(prizePicture); if (!pCell) { pCell = new CCTableViewCell(); pCell->autorelease(); //1.表格背景ZF_Shoot_Button_gridItem CCSprite *pSprite = CCSprite::create("ZF_Shoot_Button_gridItem.png"); pSprite->setAnchorPoint(CCPointZero); pSprite->setPosition(CCPointZero); pSprite->setScale(1); pCell->addChild(pSprite); //2.prizePicture pCell->removeChildByTag(122); pCell->addChild(prizePicture); //3.coinName CCLabelTTF *pLabeName = CCLabelTTF::create(this->coinName[idx].c_str(), "Arial", 28); pLabeName->setPosition(ccp(20, 10)); pLabeName->setColor(ccc3(88, 88, 88)); pLabeName->setAnchorPoint(CCPointZero); pLabeName->setTag(123); pCell->addChild(pLabeName); //4.prizePrice char priceChar[11]; sprintf(priceChar, "%d",this->coinListPrice[idx]); string t1 = "¥"; t1 = t1 + priceChar; CCLabelTTF *pLabelPrice = CCLabelTTF::create(t1.c_str(), "Arial", 28); pLabelPrice->setPosition(ccp(tableCellSize.width*0.37, tableCellSize.height*0.8)); pLabelPrice->setAnchorPoint(CCPointZero); pLabelPrice->setTag(124); pLabelPrice->setColor(ccc3(250, 131, 26)); pCell->addChild(pLabelPrice); //5.购买 CCMenuItemImage *itemImage = CCMenuItemImage::create("ZF_Shoot_button_coinList_buy1.png", "ZF_Shoot_button_coinList_buy2.png", this, menu_selector(MallMarkets::menuItemCall2)); if (itemImage->getTag() == -1) { itemImage->setTag(idx); } itemImage->setPosition(ccp(tableCellSize.width*0.4, tableCellSize.height*0.42)); CCMenu *menu = CCMenu::create(itemImage,NULL); menu->setPosition(CCPointZero); pCell->addChild(menu, 1); }else{ pCell->removeChildByTag(122); pCell->addChild(prizePicture); CCLabelTTF *pLabeName = (CCLabelTTF*)pCell->getChildByTag(123); pLabeName->setString(this->coinName[idx].c_str()); char priceChar[11]; sprintf(priceChar, "%d",this->coinListPrice[idx]); string t1 = "¥"; //string t2 = "元人民币"; //t1 = t1 + priceChar + t2; t1 = t1 + priceChar; CCLabelTTF *pLabelPrice = (CCLabelTTF*)pCell->getChildByTag(124); pLabelPrice->setString(t1.c_str()); } return pCell; }