关于UIAlertController的使用(swift)

本文介绍如何在iOS应用中使用UIAlertController来替代UIAlertView创建警告框。通过一个具体的Swift代码示例,展示了如何设置警告框的标题、消息内容以及不同的操作按钮,并实现点击后的响应动作。

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

今天在学习使用UIAlertController时候发现了很多问题,在网上学习时候,可能是资料比较早的缘故,还是使用UIAlertView作为警告框.由于初学,并不知道在ios8之后改为UIAlertController,查阅资料以及阅读文档之后遂尝试使用新方法调用警告框,但是由于对于移动端开发不熟悉,对于文档也不太熟,一直没法实现这个函数,后来在stackoverflow上边发现了类似的方法,故加以借鉴,如下

   @IBActionfunc stopButton(sender: UIButton){

        //loading.stopAnimating()

        let Alert =UIAlertController(title: "警告",message:"正在下载,确定要取消下载吗", preferredStyle:UIAlertControllerStyle.Alert)

        let noCancel =UIAlertAction(title: "", style: .Default) { (UIAlertAction) ->Void inprint("click no")

        }

        let yesCancel =UIAlertAction(title: "", style: .Cancel, handler:alertView)

            Alert.addAction(noCancel)

            Alert.addAction(yesCancel)

            self.presentViewController(Alert, animated:true, completion: nil)

        

        

    }

    func alertView(alert:UIAlertAction) {

        

      

            

            loading.stopAnimating()

        

         }

在点击停止按钮之后,会弹出警告框,询问是否停止下载,点击是,下载结束,点击否,继续下载.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值