1

UIAlertView 内に挿入したいテキスト フィールドに等しい文字列があります。

NSString *finalScore = [[NSString alloc] initWithFormat:[counter2 text]];

UIAlertView *myAlertView = [[UIAlertView alloc]
                                initWithTitle:finalScore
                                message:@"You scored X points"
                                delegate:self
                                cancelButtonTitle:nil
                                otherButtonTitles:@"OK", nil];

[myAlertView show];
[myAlertView release];

「X」を文字列「finalScore」のスコアに置き換えたい

メッセージセクションの下に引用符を付けずに文字列名を入力するだけですが、文字列と一緒にテキストも必要です。

たくさんありがとう、チェイス

4

3 に答える 3

4

message:パラメータを次のように置き換えます。

message:[NSString stringWithFormat:@"You scored %@ points", finalScore]

また、元のコードでは、引数なしで文字列の書式設定を使用していることに注意してくださいfinalScore。これは、ノーオペレーションまたは安全ではありません (%シンボルが含まれている場合)。オブジェクトもリークしていfinalScoreます。

于 2009-09-16T20:30:20.763 に答える
1

次のようなことを試して、それをmessage変数として UIAlertView の初期化に渡します。

NSString* message = [NSString stringWithFormat:@"You scored %@ points",
                              [counter2 text]];

から出力されるタイプに応じて、書式設定文字列に関する詳細を変更する[counter2 text]必要がある場合がありますが、遭遇する多くのケースでは上記が機能するはずです。

于 2009-09-16T20:32:00.073 に答える
0

それ以外の:

@"You scored X points"

使用する:

[NSString stringWithFormat:@"You scored %@ points", finalScore]
于 2009-09-16T20:30:10.360 に答える