iOS---弹出提示对话框的封装
2016-09-20 16:21
183 查看
iOS—弹出提示对话框的封装
一、就一个选项的对话框代码块
#pragma mark - 封装弹出对话框方法 // 提示错误信息 - (void)showError:(NSString *)errorMsg { // 1.弹框提醒 // 初始化对话框 UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:errorMsg preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]]; // 弹出对话框 [self presentViewController:alert animated:true completion:nil]; }
需要调用弹出对话框方法的地方使用的代码如下:
代码块
// 弹出“请检查用户名和密码是否为空!”对话框 [self showError:@"请检查用户名和密码是否为空!"];
效果如图所示:
二、如果是要做两个选项的对话框
先在.h文件中定义如下:
@property (strong, nonatomic) UIAlertAction *okAction; @property (strong, nonatomic) UIAlertAction *cancelAction;
然后在.m文件中写入如下代码:
#pragma mark - 注销:弹出对话框 - (void) logout { // 初始化对话框 UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"确认注销吗?" preferredStyle:UIAlertControllerStyleAlert]; // 确定注销 _okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) { // 1.清除用户名、密码的存储 // 2.跳转到登录界面 [self performSegueWithIdentifier:@"Logout" sender:nil]; }]; _cancelAction =[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]; [alert addAction:_okAction]; [alert addAction:_cancelAction]; // 弹出对话框 [self presentViewController:alert animated:true completion:nil]; }
需要调用弹出对话框方法的地方使用的代码如下:
代码块
// 弹出“确认注销吗?”对话框 [self logout];
效果如图所示:
更多JAVA、Unity3D的文章,请点击:
http://blog.csdn.net/u010841622
相关文章推荐
- iOS弹出对话框提示字符串消息
- iOS项目开发实战——弹出提示对话框
- iOS---弹出提示对话框
- 跳转前弹出提示对话框
- 对话框弹出错误提示
- 出错时弹出提示对话框
- 出错时弹出提示对话框
- 在Asp.net中如何实现弹出提示对话框
- asp.net弹出对话框的封装
- 多次弹出提示对话框,根据选择的值操作下一步.
- DataGrid中全选删除按钮,如果没选,先提示没有选择,再弹出确定删除对话框的例子
- ASP.NET基础教程-给命令按钮添加弹出提示对话框
- 在Asp.net中如何实现弹出提示对话框
- 关于捕捉session 过期并弹出对话框提示的问题
- C#调用系统Dll,弹出提示对话框
- 在Asp.net中如何实现弹出提示对话框
- 在Asp.net中如何实现弹出提示对话框
- 拷贝出弹出对话框, 错误提示窗口中的文字
- 在Asp.net中如何实现弹出提示对话框()
- 右下角老弹出盗版提示,以及登录界面出现正版验证对话框