1

ユーザーがボタンをクリックすると、テキストフィールドからのテキストを含むアラートがポップアップするアプリを作成しようとしています。しかし、試してみると、空白のアラートが表示されます。これは私のコードです:

@synthesize label;

@synthesize textBox1;

@synthesize text;

- (IBAction)buttonClick {
 UIAlertView *someText = [[UIAlertView alloc] initWithTitle: @"Text from textbox1" message: text delegate: self cancelButtonTitle: @"OK" otherButtonTitles: nil];
 [someText show];
 [someText release];
 text = textBox1.text;
 label.text = text;
}

私は何を間違っているのですか。すべてが適切に配置されているようです。答えは NSLog() と関係があると思います。

4

2 に答える 2

6

アラートを表示したtext、プロパティを設定しています。アラートが作成されると、おそらく に設定されます。nil

于 2010-08-13T00:01:03.283 に答える
0

UIAlertView の前に変数 test を宣言する必要があります。

text = textBox1.text;
UIAlertView *someText = [[UIAlertView alloc] initWithTitle:@"Text from Textbox1" message:text delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[someText show];

次に、アラートの textBox からテキストを取得します

于 2015-04-07T21:31:42.043 に答える