[Swift]UIKit学习之警告框:UIAlertController和UIAlertView

[Swift]UIKit学习之警告框:UIAlertController和UIAlertView,第1张

概述Important: UIAlertView is deprecated in iOS 8. (Note that UIAlertViewDelegate is also deprecated.) To create and manage alerts in iOS 8 and later, instead use UIAlertController with a preferredStyle o


important:UIAlertVIEwis deprecated in iOS 8. (Note thatUIAlertVIEwDelegateis also deprecated.) To create and manage alerts in iOS 8 and later,instead useUIAlertControllerwith apreferredStyleofUIAlertControllerStyleAlert.


在Xcode7中使用UIAlertVIEw会报如下警告:

'UIAlertVIEw'wasdeprecated iniOS9.0: UIAlertVIEwisdeprecated. UseUIAlertControllerwith apreferredStyleof UIAlertControllerStyleAlert instead


Alert VIEws :Alert vIEws display a concise and informative alert message to the user.

UIAlertController同时替代了UIAlertVIEw和UIActionSheet,从系统层级上统一了 alert 的概念 —— 即以 modal 方式或 popover 方式展示。

//VIEwController.swiftimportUIKitclassVIEwController:UIVIEwController{overrIDefuncvIEwDIDLoad(){super.vIEwDIDLoad()//DoanyadditionalsetupafterloadingthevIEw,typicallyfromanib.//创建一个buttonletbutton=UIbutton(type:UIbuttonType.Custom)//初始化UIbuttonbutton.frame=CGRectMake(50,100,150,50)//创建一个CGRect,设置位置和大小button.backgroundcolor=UIcolor.greencolor()//设置背景色button.setTitle("点击显示d窗",forState:UIControlState.normal)//设置标题//传递触摸对象(点击事件)button.addTarget(self,action:"buttonpressed:",forControlEvents:UIControlEvents.touchUpInsIDe)self.vIEw.addSubvIEw(button)}//Actionfuncbuttonpressed(sender:UIbutton){showAlertreset()}funcshowAlertDefault(){letalertController=UIAlertController(Title:"d窗标题",message:"Hello,这个是UIAlertController的默认样式",preferredStyle:UIAlertControllerStyle.Alert)letcancelAction=UIAlertAction(Title:"取消",style:UIAlertActionStyle.Cancel,handler:nil)letokAction=UIAlertAction(Title:"好的",style:UIAlertActionStyle.Default,handler:nil)letresetAction=UIAlertAction(Title:"重置",style:UIAlertActionStyle.Destructive,handler:nil)alertController.addAction(resetAction)alertController.addAction(cancelAction)alertController.addAction(okAction)self.presentVIEwController(alertController,animated:true,completion:nil)}funcshowAlertreset(){letalertControl=UIAlertController(Title:"d窗的标题",showAlertreset",preferredStyle:UIAlertControllerStyle.Alert)letcancelAction=UIAlertAction(Title:"取消 *** 作",handler:nil)alertControl.addAction(cancelAction)alertControl.addAction(okAction)self.presentVIEwController(alertControl,completion:nil)}overrIDefuncdIDReceiveMemoryWarning(){super.dIDReceiveMemoryWarning()//dispoSEOfanyresourcesthatcanberecreated.}}


参考:

http://www.jianshu.com/p/86f933850df8

http://www.jb51.cc/article/p-dhtbmglj-bgr.html

总结

以上是内存溢出为你收集整理的[Swift]UIKit学习之警告框:UIAlertController和UIAlertView全部内容,希望文章能够帮你解决[Swift]UIKit学习之警告框:UIAlertController和UIAlertView所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1083467.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存