UIAlertView

  我感觉UIActionSheet和UIAlertView的用法差不多,想用哪个,根据公司要求和个人爱好。

 

#import "ViewController.h"

@interface ViewController ()<UIAlertViewDelegate>

@end

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];

    button1.frame = CGRectMake(100, 100, 100, 50);

    button1.backgroundColor = [UIColor lightGrayColor];

    [button1 setTitle:@"button1" forState:UIControlStateNormal];

    [button1 addTarget:self action:@selector(showAlertView:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:button1];

}

 

- (void)showAlertView:(UIButton*)button {

  //Cancel,OK1,OK2,OK3,它们的buttonIndex分别为0,1,2,3

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Hehe" message:@"这是一行描述信息" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK1",@"OK2",@"OK3", nil];

    alertView.delegate = self;

    [alertView show];

}

 

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    if (0 == buttonIndex) {

        NSLog(@"0000000000");

    } else if (1 == buttonIndex) {

        NSLog(@"1111111111");

    } else if (2 == buttonIndex) {

        NSLog(@"2222222222");

    } else {

        NSLog(@"3333333333");

    }

}

 

- (void)alertViewCancel:(UIAlertView *)alertView{

    NSLog(@"alertViewCancel");

}

 

-(void)willPresentAlertView:(UIAlertView *)alertView{

    NSLog(@"willPresentAlertView");

}// before animation and showing view

 

- (void)didPresentAlertView:(UIAlertView *)alertView{

    NSLog(@"didPresentAlertView");

}// after animation

 

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex{

    NSLog(@"willDismissWithButtonIndex");

}// before animation and hiding view

 

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{

    NSLog(@"didDismissWithButtonIndex");

}// after animation

 

// Called after edits in any of the default fields added by the style

- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView{

    NSLog(@"alertViewShouldEnableFirstOtherButton");

    return YES;

}

@end

 

posted on 2015-08-15 17:42  乱七八糟21号  阅读(141)  评论(0编辑  收藏  举报

导航