0

我需要设置语言

我有:

#define kMenuSettingsHeaderrus @"Настройки"
#define kMenuSettingsHeadereng @"Settings"

我想使用这个全局变量将字符串设置为标签,具体取决于

_language= [[SettingsManager sharedSettingsManager] getLanguage];

_language can be @"rus" or @"eng"

CCLabelTTF *settingsLabel = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"kMenuSettingsHeader%@",_language] fontName:kLabelFontNameTTF fontSize:kMenuHeaderFontSize];

你能帮我吗,在php中我这样做就像$$

一个来自 php 的例子:

$a = "hello";
$$a = "world"; => $hello="world"
4

1 回答 1

1

你正在做的事情会给出 kMenuSettingsHeadereng 或 kMenuSettingsHeaderrus 作为结果,因为它们将被视为字符串而不是宏......所以使用这个

#define kMenuSettingsHeaderrus @"Настройки"
#define kMenuSettingsHeadereng @"Settings"


_language= [[SettingsManager sharedSettingsManager] getLanguage];

CCLabelTTF *settingsLabel;
 if ([_langueage isEqualToString:@"rus"])
{
settingsLabel = [CCLabelTTF labelWithString:kMenuSettingsHeaderrus fontName:kLabelFontNameTTF fontSize:kMenuHeaderFontSize];
}
else if ([_langueage isEqualToString:@"eng"])
{
settingsLabel = [CCLabelTTF labelWithString:kMenuSettingsHeadereng fontName:kLabelFontNameTTF fontSize:kMenuHeaderFontSize];
}

检查语法...我没有 X 代码来检查...希望这会有所帮助.. :)

于 2012-05-04T06:26:56.027 回答