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