我不知道如何删除我的标签字符串。事情是这样的,你按下一个按钮并删除标签,添加下一个标签(与后退按钮相同) 这是按下下一个/后退按钮时启动的方法:
-(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,但没有出现。
感谢阅读!
答案 0 :(得分: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];