我试图制作一个带有.plist
字符串数组的标签,但是当我运行我的应用程序时,我没有得到任何答案。这是我的代码:
NSString* plistPath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"NamesLevel%d",tag] ofType:@"plist"];
NSArray* contentArray = [NSArray arrayWithContentsOfFile:plistPath];
有了这个,我想拿起(逐个)我的8个字符串并将它们放在标签中:
CCLabelTTF *Name = [CCLabelTTF labelWithString:[contentArray objectAtIndex:currentIndexSelected] fontName:CUSTOM_FONT_NAME fontSize:80];
Name.position = ccp(500, 220);
[self addChild:Name];
这将使用2个按钮(下一个/后退)逐个更改字符串。
我的代码有问题吗?
编辑2: 这是我的下一个按钮的实现,以便在按下时更改我的标签:
NSString* plistPath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"NamesLevel%d", currentIndexSelected] ofType:@"plist"];
NSArray* contentArray = [NSArray arrayWithContentsOfFile:plistPath];
CCLabelTTF *Name = [CCLabelTTF labelWithString:[contentArray objectAtIndex:labelpos] fontName:CUSTOM_FONT_NAME fontSize:80];
修改
其中一个plist
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>Dog</string>
<string>Cat</string>
<string>Mouse</string>
<string>Spike</string>
<string>Monster</string>
<string>Snake</string>
<string>Fish</string>
<string>Meat</string>
</array>
</plist>