0

ハイスコ​​ア ページの 2 番目のビューを持つスロット マシン プロジェクトを設計しています。ほとんどの場合、スロット マシンからハイ スコア ページへの勝者のパスを除いて、すべてが機能しています。スロットマシン内のメソッドのコードは次のとおりです。

if(win == YES)  {
    NSString *msg = nil;
    if(playerField.text.length > 0) {
        msg = [[NSString alloc] initWithFormat:@"%@", playerField.text];
    }
    NSLog(@"DEBUG");
    [(HighScorePage *)self.view addNewHighScore:msg];
    [self performSelector:@selector(playWinSound) withObject:nil afterDelay:.5];
    [msg release];
}

そして、HighScorePage の addNewHighScore メソッドは次のとおりです。

-(void)addNewHighScore:(NSString *)player   {
NSMutableArray *tempArray = [[NSMutableArray alloc] init];

int i = 0;
for (NSArray *count in dynPlayerArray) {
    [tempArray addObject:[NSIndexPath indexPathForRow:i++ inSection:0]];
}
[tempArray addObject:player];
[[self highScores] beginUpdates];
[[self highScores] insertRowsAtIndexPaths:(NSArray *)tempArray withRowAnimation:UITableViewRowAnimationNone];
[[self highScores] endUpdates];

[tempArray release];    

}

これはまだ新しいので、あなたの考えを教えてください!ありがとう!

4

2 に答える 2

0

コメントで、あるクラスから別のクラスに文字列を渡す方法を尋ねましたが、ここに答えがあります-

クラス B からクラス A に文字列値を渡したい場合は、クラス A の .h ファイルで NSMutableString インスタンスを作成し、それをプロパティとして次のように定義します。

NSString *stringVar;

@property (nonatomic, retain) NSString *stringVar;

and also synthesize this property in class A's .m file for setter & getter as-

@ synthesize stringVar;

次に、クラス B でこの文字列にクラス A のプロパティとしてアクセスし、クラス B からクラス A に渡したい値を割り当てます。

これがあなたを助けることを願っています。また、プロパティルックの詳細については -

http://developer.apple.com/library/Mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html#//apple_ref/doc/uid/TP30001163-CH17-SW1enter code here

于 2011-04-07T16:12:31.413 に答える
0

私に言わせれば、ハイスコア データは、たとえばシングルトンのように、誰もがアクセスできるモデル クラスにある必要があります。

プレーヤーが勝つと、スロット ViewController がこのモデル クラスに新しいハイ スコアを挿入し、キー値の監視または通知のいずれかを使用して、ハイ スコア ビュー自体を更新する必要があります。

于 2011-04-06T16:26:48.007 に答える