我有一个UIWindow,我用它来显示另一个UIWindow,它的rootViewController表示一个UIAlertController。当我关闭UIAlertController时,主窗口没有响应,我不确定为什么。下面是我的实现:
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)
}发布于 2016-02-16 12:55:12
明白了。刚刚在cancel的完成处理程序中调用了window.hidden = true。我想我只是想多了。:)
https://stackoverflow.com/questions/35422385
复制相似问题