栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

防止解雇UIAlertController

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

防止解雇UIAlertController

您是正确的:如果用户可以点击警报中的按钮,则警报将被关闭。因此,您要防止用户点击按钮!只需禁用UIalertAction按钮即可。如果禁用了警报操作,则用户无法点击它以将其关闭。

要将其与文本字段验证结合使用,请使用文本字段委托方法或操作方法(在创建时在文本字段的配置处理程序中配置),以根据输入(或未输入)文本适当地启用/禁用UIalertActions

这是一个例子。我们创建了这样的文本字段:

alert.addTextFieldWithConfigurationHandler {    (tf:UITextField!) in    tf.addTarget(self, action: "textChanged:", forControlEvents: .EditingChanged)}

我们有一个“取消”操作和一个“确定”操作,并将“确定”操作带入了残疾人世界:

(alert.actions[1] as UIalertAction).enabled = false

随后,除非文本字段中有一些实际的文本,否则用户无法点击“确定”:

func textChanged(sender:AnyObject) {    let tf = sender as UITextField    var resp : UIResponder = tf    while !(resp is UIalertController) { resp = resp.nextResponder() }    let alert = resp as UIalertController    (alert.actions[1] as UIalertAction).enabled = (tf.text != "")}

编辑 这是上述代码的当前(Swift 3.0.1及更高版本)版本:

alert.addTextField { tf in    tf.addTarget(self, action: #selector(self.textChanged), for: .editingChanged)}

alert.actions[1].isEnabled = false

@objc func textChanged(_ sender: Any) {    let tf = sender as! UITextField    var resp : UIResponder! = tf    while !(resp is UIalertController) { resp = resp.next }    let alert = resp as! UIalertController    alert.actions[1].isEnabled = (tf.text != "")}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/436436.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号