LoginSignup
10
10

More than 5 years have passed since last update.

複数のUIAlertViewを使う時のclickedButtonAtIndex

Posted at

.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;
        }
    }
}
10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10