2012-02-16 3 views
0

私はUIAlertViewStylePlainTextInputに固執しています。 (私のコードはここに投稿するには時間がかかりすぎますが、これは問題が存在する部分です)。それはすべて機能しますが、プログラムはユーザーが情報を入力して続行するまで待機しません。 "editName"ボタンは下のコードの表示を変更しませんが、updateDisplayボタンはうまくいきます( "updateDisplay"を押す前に "editName"ボタンを押した場合)。ユーザーが情報を入力する(または取り消す)まで、すべてを停止するようにするにはどうすればよいですか。あるいは、私が行く必要のある場所に私を連れて行く別のリードがあります。 (私は - (void)alertViewにコードの残りの部分を置いていますが、これは正しい方法ではないようです)。UIAlertViewStylePlainTextInput - ユーザーからのテキスト入力を待つことなく、プログラムが続行します。

ありがとうございます。

#import "HSTestViewController.h" 

@implementation HSTestViewController 
@synthesize display; 

NSString *newName; 

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 

{  
    if (buttonIndex == 1) 
    { 
     newName = [[alertView textFieldAtIndex:0] text]; 
    } 
} 


- (void) getNewName; 
{ 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You made the High Score List" 
               message:@"Please enter your name" 
               delegate:self 
             cancelButtonTitle:@"Cancel" 
             otherButtonTitles:@"Ok", nil]; 

    alert.alertViewStyle = UIAlertViewStylePlainTextInput; 
    [alert show]; 
} 

- (IBAction)editName:(id)sender 
{ 
    [self getNewName];  
    newName = display.text; 
} 

- (IBAction)updateDisplay:(id)sender 
{ 
    display.text = newName; 
} 

@end 

答えて

2

UIAlertViewDelegateをクラスに追加します。そして、以下のデリゲートメソッドを実装します。

あなたのケースでは、OKボタンのインデックス値は1になります。

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (buttonIndex) 
    { 
     // call the method or the stuff which you need to perform on click of "OK" button. 
    } 
} 

これが役に立ちます。

+0

ありがとうございます。あなたが提案したようなものをいくつか動かしました。今では私のプログラムは、今私がそれを意図したものとまったく同じようになりました。私はUIAlertViewDelegateも追加しました。 – ShadowDES

関連する問題