Here is a short sample. I recommend just trying to write some code yourself and then post what problems you have with it. This definitely makes answering questions easier. You can also create your own subclass CCTableViewCellif you wish.
Header File, SampleTableView.h
#import "cocos2d.h"
#import "cocos2d-ui.h"
@interface SampleTableView : CCNode <CCTableViewDataSource>
@end
Source file: SampleTableView.m
float const kNumberOfRows = 30.0f;
@implementation SampleTableView
- (instancetype)init
{
self = [super init];
if (self) {
CCTableView* table = [CCTableView node];
table.dataSource = self;
table.block = ^(CCTableView* table) {
NSLog(@"Cell %d was pressed", (int) table.selectedRow);
};
[self addChild:table];
}
return self;
}
- (CCTableViewCell*) tableView:(CCTableView*)tableView nodeForRowAtIndex:(NSUInteger) index {
CCTableViewCell* cell = [CCTableViewCell node];
cell.contentSizeType = CCSizeTypeMake(CCSizeUnitNormalized, CCSizeUnitUIPoints);
cell.contentSize = CGSizeMake(1.0f, 32.0f);
float colorFactor = (index / kNumberOfRows);
CCNodeColor* colorNode = [CCNodeColor nodeWithColor:[CCColor colorWithRed:colorFactor green:(1.0f - colorFactor) blue:(0.2f + 0.5 * colorFactor) ] width:100.0f height:18.0f];
[cell addChild:colorNode];
return cell;
}
- (NSUInteger) tableViewNumberOfRows:(CCTableView*) tableView {
return kNumberOfRows;
}
:
SampleTableView* table = [SampleTableView node];
table.contentSizeType = CCSizeTypeNormalized;
table.contentSize = CGSizeMake(1.0, 1.0);
, :
