IOS弹出提示框(确认/取消)

在移动开发之中,系统弹出提示框是很常见的需求,比如,账户密码输入不正确的时候,给予客户提示“输入不正确,请再次输入!“;
此文章不做详细的描述,因为这个东西的话,也很简单,如果要以其他方式实现,可以去网上找其他的文档;

一:封装的方法

- (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:@"用户名和密码是否为空?"];

ok,简单吧。这样实现了IOS的弹出提示框;

如果需要点击(确定,取消的按钮)提示框,两个进行选择按钮的话,可以看如下代码:
mian.h定义:

@property (strong, nonatomic) UIAlertAction *okAction;
@property (strong, nonatomic) UIAlertAction *cancelAction;

main.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];//调用弹出框

两个弹出框的案例都可行,博主就不贴图片了,复制上去就可以看效果啦!

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值