Help us understand the problem. What is going on with this article?

複数のUIAlertViewを使う時のclickedButtonAtIndex

More than 5 years have passed since last update.

.hに必要なUIAlertViewを書いておく

UIAlertView *firstAlert;
UIAlertView *secondAlert;

アラートを呼び出すところに

firstAlert = [[UIAlertView alloc] initWithTitle:@"タイトル" message:@"メッセージ" delegate:self cancelButtonTitle:@"いいえ" otherButtonTitles:@"はい", nil];
[firstAlert show];

デリゲートメソッドclickedButtonAtIndexを使う

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if(firstAlert == alertView){
        switch (buttonIndex) {
            case 0:
                NSLog(@"firstAlertのいいえをクリックしました");
                break;
            case 1:
                NSLog(@"firstAlertのはいをクリックしました");
                break;
        }
    } else if(secondAlert == alertView){
        switch (buttonIndex) {
            case 0:
                NSLog(@"secondAlertのいいえをクリックしました");
                break;
            case 1:
                NSLog(@"secondAlertのはいをクリックしました");
                break;
        }
    }
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away