Edited at

Storyboardを使わずにUIAlertViewを表示させる。

More than 3 years have passed since last update.

スクリーンショット 2015-04-19 午後7.56.53.png

storyboardを使わずにUIAlertViewを作成するには以下のようになる。この時,それぞれのbuttonIndexは

cancelButtonTitles が 0(cancel)

otherButtonTitles が 順に1(other1),2(other2)

となる。

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Title"
message:@"Message"
delegate:self
cancelButtonTitle:@"cancel"
otherButtonTitles:@"other1",@"other2",nil];

[alert show];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

-(void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
NSLog(@"1");

}else if (buttonIndex == 2){
NSLog(@"2");
}else if (buttonIndex == 0){
NSLog(@"0");
}

}

@end