私は国でアプリを作っています、そしてそれは旗です。今、私は問題を抱えています。私は1から200までの名前のフラグを持っています。そして数字のすべての名前。(たとえば、1はオーストラリア、2は米国です)。ランダムを使用して。にフラグを表示しますUIImageView
。その後、4つのボタンがあり、フラグ名から名前になります。最後にすべてのコード。
画像の名前を格納する配列があります。
- 画像の名前を格納する配列があります。
- そして、ボタンの名前が付いたファイル。
そして質問:国の番号を名前に置き換えるにはどうすればよいですか? ファイルからすべての名前をNSDictionaryに入れる方法は?または、そのような機能を使用するにはどうすればよいですか?
英語でごめんなさい。:)nextFlagを作成する関数のコード。
- (void)nextFlag
{
int tmp = random() % [avalibleFlags count];
NSString *imgString = [avalibleFlags objectAtIndex:tmp];
NSString *path = [[NSBundle mainBundle] pathForResource:imgString ofType:@"png"];
UIImage *newImage = [UIImage imageWithContentsOfFile:path];
currentFlagName = imgString;
[_currentFlag setImage:newImage];
[avalibleFlags removeObjectAtIndex:tmp];
NSMutableArray *tmpFlags = [allFlags mutableCopy];
[tmpFlags removeObjectAtIndex:tmp];
for (int i=0; i<3; i++)
{
int tmpNumber = random() % [tmpFlags count];
NSString *stringForButton = [tmpFlags objectAtIndex:tmpNumber];
[tmpFlags removeObjectAtIndex:tmpNumber];
[buttonNames insertObject:stringForButton atIndex:i];
}
int tmp2 = random() % 4;
[[_buttons objectAtIndex:tmp2] setTitle:imgString forState:UIControlStateNormal];
for (int i = 0, j = 0; i<4; i++) {
if ([[_buttons objectAtIndex:i] currentTitle] != currentFlagName)
{
[[_buttons objectAtIndex:i] setTitle:[buttonNames objectAtIndex:j] forState:UIControlStateNormal];;
j++;
}
}
}