UIAlertViewのボタンが押された時の処理
手順
ViewController.h
#import <UIKit/UIKit.h> @interface ViewController : UIViewController <UIAlertViewDelegate> @end
ViewController.m
#import "ViewController.h" @interface ViewController () @end @implementation ViewController // いろいろ省略 - (void)viewDidLoad { // デリゲートをselfにセットします // cancelButtonTitle,otherButtonTitlesを設定 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"アラートのタイトル" message:@"アラート本文" delegate:self cancelButtonTitle:@"いいえ" otherButtonTitles:@"まあまあ", @"はい", nil]; [alert show]; } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { switch (buttonIndex) { case 0: // 1番目のボタン「いいえ」が押されたとき break; case 1: // 2番目のボタン「まあまあ」が押されたとき break; case 2: // 3番目のボタン「はい」が押されたとき break; default: break; } } @end