0

我不知道如何删除我的标签字符串。事情是这样的,按下下一个按钮并删除标签,添加下一个标签(与后退按钮相同)这是按下下一个/后退按钮时启动的方法:

-(void)showStoryContentWithIndex:(int)index
{
    [self removeChild:card cleanup:YES];

    NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"Names" ofType:@"plist"];
    NSArray* contentArray = [NSArray arrayWithContentsOfFile:plistPath];

    CCLabelTTF *truckName = [CCLabelTTF labelWithString:[contentArray objectAtIndex:currentIndexSelected]  fontName:CUSTOM_FONT_NAME fontSize:80];

    truckName.position = ccp(500, 220);
    [self addChild:TName];

    NSString * cardSpriteName = [NSString stringWithFormat:@"%d.png",currentIndexSelected];
    card = [CCSprite spriteWithSpriteFrameName:cardSpriteName];
    [card setPosition:ccp (500,500)];
    [card setOpacity:255];
    [self addChild:card z:4];
}

所以,我需要实现一种删除标签的方法,我试图使用 removeChild,但那里什么也没出现。

谢谢阅读!

4

1 回答 1

0

为下一个和上一个标签保留一个 iVar,而不是删除它们,你为什么不

// in .h

CCLabelTTF *_nextLabel, *_previousLabel;

// somewhere in init 

_nextLabel = [CCLabelTTF ...];
[self addChild:_nextLabel]              
_previousLabel = [CCLabelTTF ...];
[self addChild:_previousLabel]              


// and finally, when you update 

[_nextLabel setString:@"new next"];
[_previousLabel setString:@"new previous"];

编辑 :

NSString* newNext = [dic objectForKey:@"keyForNext"];
[_nextLabel setString:newNext];
于 2013-03-18T12:59:43.110 回答