美文网首页
UIAlertController基本用法

UIAlertController基本用法

作者: MR_CZWang | 来源:发表于2016-09-26 10:22 被阅读0次

//UIAlertController - 提示框

/**

alertControllerWithTitle - 提示标题

message - 信息

preferredStyle - 类型

UIAlertControllerStyleActionSheet = 0,

UIAlertControllerStyleAlert

*/

UIAlertController *ac = [UIAlertController alertControllerWithTitle:@"提示框" message:@"无法打开.avi" preferredStyle:UIAlertControllerStyleActionSheet];

/**

*  @param UIAlertActionStyle

UIAlertActionStyleDefault = 0,

UIAlertActionStyleCancel,

UIAlertActionStyleDestructive - 摧毁的,毁灭的

*/

初始化一个按钮并且加到提示框

UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"强制打开" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

//点击按钮之后要执行的东西

}];

//按钮添加到AlertController

[ac addAction:action1];

UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"强制关闭" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {

//点击按钮之后要执行的东西

}];

//按钮添加到AlertController

[ac addAction:action2];

UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

//点击按钮之后要执行的东西

}];

//按钮添加到AlertController

[ac addAction:action3];

//presentViewController - 出现,显示一个viewController

//animated - 要不要动画效果

把AlertController显示到控制器上

[self presentViewController:ac animated:YES completion:^{

}];

相关文章

网友评论

      本文标题:UIAlertController基本用法

      本文链接:https://www.haomeiwen.com/subject/cgnsettx.html