iOS 开发中关于弹窗的几种方式

本文介绍 iOS 应用中不同版本下 UIAlertController 和 UIActionSheet 的使用方法,包括创建、显示及添加按钮等操作,适用于 iOS 开发者快速上手。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


1.IOS8以前的方式:

 UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"输入的数字不合理" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
   [alertView show];

2.IOS8以后最新方式:ios 9 推荐使用,ios7的在ios9中已过期

   *ios8创建弹框的方法:

UIAlertController *alertVc =[UIAlertController alertControllerWithTitle:@"提示" message:@"输入数字不合理" preferredStyle:UIAlertControllerStyleAlert];
   *ios8显示弹框的方法:
[self presentViewController:alertVc animated:NO completion:nil];

   *ios8添加按钮的方法:

[alertVc addAction:[UIAlertActionactionWithTitle:@"取消" style: UIAlertActionStyleCancel handler:^(UIAlertAction*action) { NSLog(@"点击了取消按钮");

3.actionsheet弹窗:(底部弹窗)

       UIActionSheet *sheet = [[UIActionSheetalloc]initWithTitle:@"确定要注销?" delegate:selfcancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:nil,nil];

       [sheet showInView:self.view];

   - (void)actionSheet:(UIActionSheet *)actionSheetclickedButtonAtIndex:(NSInteger)buttonIndex

    {

       if (buttonIndex ==0) {

           [self.navigationControllerpopViewControllerAnimated:YES];

       }

    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值