0
我已經能夠添加一個UITableView到一個cocos2d圖層,它似乎滾動和處理代理動作,如didSelectRowAtIndexPath
。將cocos2d元素添加到UITableViewCell?
但我想要的是將精靈放在桌面視圖單元格,自定義位圖字體,基本上把每個UITableViewcell作爲我可以用cocos2d元素定製的東西,但我不知道該怎麼做。
// HelloWorldLayer implementation
@implementation HelloWorldLayer
@synthesize myTableView;
+(CCScene *) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
HelloWorldLayer *layer = [HelloWorldLayer node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
// on "init" you need to initialize your instance
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if((self=[super init])) {
self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(10, 10, 300, 150) style:UITableViewStylePlain];
// Set TableView Attributes
self.myTableView.backgroundColor = [UIColor clearColor];
self.myTableView.dataSource = self;
self.myTableView.delegate = self;
self.myTableView.opaque = YES;
// Add View To Scene
[[[CCDirector sharedDirector] openGLView] addSubview:self.myTableView];
}
return self;
}
// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
// in case you have something to dealloc, do it in this method
// in this particular example nothing needs to be released.
// cocos2d will automatically release all the children (Label)
[self.myTableView release];
self.myTableView = nil;
// don't forget to call "super dealloc"
[super dealloc];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"Header";
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
CCLabelTTF *lblNumber = [CCLabelTTF labelWithString:@"12345" fontName:@"Georgia" fontSize:14];
[lblNumber setAnchorPoint:CGPointMake(0, 0.5)];
CCSprite *spriteIcon = [CCSprite spriteWithFile:@"Icon.png"];
// I want to add my the lblNumber and spriteIcon to the uitableviewcell
return cell;
}
// - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)newIndexPath
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"You selected index - %d", indexPath.row);
}
@end
因此,我的問題是 - 如何添加之類的東西精靈,自定義位圖字體和其他元素的cocos2d到一個UITableViewCell?
謝謝