LoginSignup
1
1

More than 5 years have passed since last update.

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

Last updated at Posted at 2015-04-19

スクリーンショット 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
1
1
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
1
1