头文件,SampletableVIEw.h
#import "cocos2d.h"#import "cocos2d-ui.h"@interface SampletableVIEw : CCNode <CCtableVIEwDataSource>@end
源文件:SampletableVIEw.m
float const kNumberOfRows = 30.0f;@implementation SampletableVIEw- (instancetype)init{ self = [super init]; if (self) { CCtableVIEw* table = [CCtableVIEw node]; table.dataSource = self; // make our class the data source 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); // Just a sample node that changes color with each index value 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; // just a demo}
以及如何在你好的世界场景或其他地方添加它:
SampletableVIEw* table = [SampletableVIEw node];table.contentSizeType = CCSizeTypenormalized;table.contentSize = CGSizeMake(1.0,1.0);
以下是它的样子截图:
总结以上是内存溢出为你收集整理的cocos2d-iphone – 带有cocos2d 3.0的CCTableView全部内容,希望文章能够帮你解决cocos2d-iphone – 带有cocos2d 3.0的CCTableView所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)