[英]Dismissing UIAlertController from UIWindow in UIWindow
我有一個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)
}
得到它了。 在取消的完成處理程序中僅調用window.hidden = true
。 猜猜我只是想了一下。 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.