0

アラビア語学習用のマッチングゲームを作ろうとしています。3 つの plist から 3 つの異なる配列を作成し、UIPicker を使用して情報を表示しています。配列の作成と UIPickerView への転送の間に、配列の要素をシャッフルしました。残念ながら、これにより、配列内のアイテムの最初のインデックスを追跡できなくなります。plist 内の各要素は同じ順序で (異なる言語で) リストされているため、一致を確認するために、各要素の初期インデックスを思い出すことができる必要があります。

次のシャッフル アルゴリズムを使用します。

int randomSort(id obj1, id obj2, void *context ) {
// returns random number -1 0 1
return (arc4random()%18-9);    

}

- (void)shuffle {
// call custom sort function
[list sortUsingFunction:randomSort context:nil];
[list2 sortUsingFunction:randomSort context:nil];
[list3 sortUsingFunction:randomSort context:nil];

}

および次の初期化:

NSString *arabicword = [[NSBundle mainBundle] pathForResource:@"arabicword" ofType:@"plist"];
NSString *englishword = [[NSBundle mainBundle] pathForResource:@"englishword" ofType:@"plist"];      
NSString *pronunciation = [[NSBundle mainBundle] pathForResource:@"pronunciation" ofType:@"plist"];          
list = [[NSMutableArray alloc] initWithContentsOfFile:arabicword];
list2 = [[NSMutableArray alloc] initWithContentsOfFile:englishword];
list3 = [[NSMutableArray alloc] initWithContentsOfFile:pronunciation];

助言がありますか?どんな助けでも大歓迎です:]

4

1 に答える 1

4

代わりに、新しいクラスを作成します。

@interface Word : NSObject
@property (readonly) NSString *english;
@property (readonly) NSString *arabic;
@property (readonly) NSString *pronunciation;
@end

(完全な実装は読者に任されています。)

そのクラスのインスタンスを単一の配列で使用します。:)

于 2010-12-21T18:26:55.047 に答える