【UIKit】-9-UIAlertController - IOS8 包括 alert 和 sheet


参考
http://www.cocoachina.com/ios/20141126/10320.html
http://blog.csdn.net/liangliang103377/article/details/40078015
http://www.cocoachina.com/ios/20141219/10701.html


A UIAlertController object displays an alert message to the user. This class replaces the UIActionSheet and UIAlertView classes for displaying alerts. After configuring the alert controller with the actions and style you want, present it using the presentViewController:animated:completion: method. In addition to displaying a message to a user, you can associate actions with your alert controller to give the user a way to respond. For each action you add using the addAction: method, the alert controller configures a button with the action details. When the user taps that action, the alert controller executes the block you provided when creating the action object. Listing 1 shows how to configure an alert with a single action.
一个UIAlertController对象显示一个警告信息给用户。该类取代UIActionSheet和U​​IAlertView类显示警报。配置你想要的动作和风格报警控制器后,使用presentViewController目前它:动画:完成:方法。除了显示一个消息给用户,你可以行动,您的警报控制器关联到给用户的方式来回应。对于每一个动作您添加使用的addAction:方法,警报控制器配置与操作的详细信息按钮。当用户点击该动作时,警报控制器执行创建操作对象时,你所提供的块。清单1显示了如何配置一个警报,一个动作。

简单使用,

    UIAlertController *alc = [UIAlertController alertControllerWithTitle:@"title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];

 

    UIAlertAction *cancel =[UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

        NSLog(@"cancel");

    }];

    UIAlertAction *ok = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

        NSLog(@"ok");

    }];

    UIAlertAction *ok2 = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

        NSLog(@"ok2");

    }];

   

    [alc addAction:cancel];

    [alc addAction:ok];

    [alc addAction:ok2];

 

    [self presentViewController:alc animated:YES completion:nil];

    



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值