您的位置:首页 > 产品设计 > UI/UE

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

2015-07-22 12:50 645 查看
参考 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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: