加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – 如何从UIAlertController的UIAlertAction处理程序中解

发布时间:2020-12-14 05:39:08 所属栏目:百科 来源:网络整理
导读:我想向用户提供一个简单的UIAlertController,其中一个选项触发关闭父视图控制器.这是我正在使用的代码: let alert = UIAlertController(title: title,message: message,preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title
我想向用户提供一个简单的UIAlertController,其中一个选项触发关闭父视图控制器.这是我正在使用的代码:
let alert = UIAlertController(title: title,message: message,preferredStyle: UIAlertControllerStyle.Alert)

    alert.addAction(UIAlertAction(title: "Close View",style: UIAlertActionStyle.Destructive,handler: {
        action in

        self.dismissViewControllerAnimated(true,completion: nil)
    }))

    alert.addAction(UIAlertAction(title: "CANCEL",style: UIAlertActionStyle.Cancel,handler: nil))

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

它没有任何影响.执行“关闭视图”处理程序后,显示警报的视图控制器仍然存在.

我还在UIAlertAction操作块中尝试了self.navigationController?.dismissViewControllerAnimated(true,completion:nil),但这也无效.

运用
self.navigationController?.popViewControllerAnimated(true)

代替

self.dismissViewControllerAnimated(true,completion: nil)

根据需要工作并关闭显示警报的视图控制器.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读