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

来源:互联网 发布:暂停非正规网络问诊 编辑:程序博客网 时间:2024/06/03 06:14

参考
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 = [UIAlertControlleralertControllerWithTitle:@"title"message:@"message"preferredStyle:UIAlertControllerStyleAlert];

 

    UIAlertAction *cancel =[UIAlertActionactionWithTitle:@"cancel"style:UIAlertActionStyleCancelhandler:^(UIAlertAction *action) {

        NSLog(@"cancel");

    }];

    UIAlertAction *ok = [UIAlertActionactionWithTitle:@"ok"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction *action) {

        NSLog(@"ok");

    }];

    UIAlertAction *ok2 = [UIAlertActionactionWithTitle:@"ok"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction *action) {

        NSLog(@"ok2");

    }];

   

    [alc addAction:cancel];

    [alc addAction:ok];

    [alc addAction:ok2];

 

    [self presentViewController:alc animated:YEScompletion:nil];

    



0 0
原创粉丝点击