IOS UIAlertController使用

答:废话不多说直接上代码。如下所示:

/*

类方法快速创建一个提示控制器 值得注意的是这个控制器有个preferreStyle属性你可以根据这个属性来确定是使用UIAlertView 还是 UIActionSheet

UIAlertControllerStyleActionSheet

UIAlertControllerStyleAlert

*/

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"显示的标题" message:@"标题的提示信息" preferredStyle:UIAlertControllerStyleAlert];

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

NSLog(@"点击取消");

}]];

[alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

NSLog(@"点击确认");

}]];

[alertController addAction:[UIAlertAction actionWithTitle:@"警告" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {

NSLog(@"点击警告");

}]];

[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {

NSLog(@"添加一个textField就会调用 这个block");

}];

// 由于它是一个控制器 直接modal出来就好了

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


原文:http://www.cnblogs.com/zhangguoliang1992/p/4918684.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容