首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >正在从UIWindow中的UIWindow中清除UIAlertController

正在从UIWindow中的UIWindow中清除UIAlertController
EN

Stack Overflow用户
提问于 2016-02-16 10:02:26
回答 1查看 586关注 0票数 0

我有一个UIWindow,我用它来显示另一个UIWindow,它的rootViewController表示一个UIAlertController。当我关闭UIAlertController时,主窗口没有响应,我不确定为什么。下面是我的实现:

代码语言:javascript
复制
func buttonPressed() {

        var window = UIWindow(frame: UIScreen.mainScreen().bounds)

        let alert = UIAlertController(title: "Add a comment to your post?", message: "You can also tag your friends.", preferredStyle: UIAlertControllerStyle.Alert)

        let cancel = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: { (action) -> Void in

            // this isn't working
            window.rootViewController?.dismissViewControllerAnimated(true, completion: nil)
            window.removeFromSuperview()



        })

        let ok = UIAlertAction(title: "Yes", style: UIAlertActionStyle.Default, handler: { (action) -> Void in

            // do something

        })

        alert.addAction(ok)
        alert.addAction(cancel)
        alert.addTextFieldWithConfigurationHandler({(txtField: UITextField) in
            txtField.placeholder = "What's on your mind?"
            txtField.keyboardType = UIKeyboardType.Default
            txtField.autocapitalizationType = .None
        })



        window.rootViewController = UIViewController()
        window.backgroundColor = UIColor.clearColor()
        window.makeKeyAndVisible()
        window.rootViewController?.presentViewController(alert, animated: true, completion: nil)
        self.addSubview(window)

        self.repostButton.setTitle("Pressed!", forState: UIControlState.Normal)

    }
EN

回答 1

Stack Overflow用户

发布于 2016-02-16 12:55:12

明白了。刚刚在cancel的完成处理程序中调用了window.hidden = true。我想我只是想多了。:)

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35422385

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档