视图控制器位于导航控制器内,是堆栈中的第二个.
我想出了以下代码:
@IBAction func logout() { let logoutAlert = UIAlertController.init(Title: "Log out",message: "Are you sure ?",preferredStyle:.Alert) logoutAlert.addAction(UIAlertAction.init(Title: "Yes",style: .Default) { (UIAlertAction) -> VoID in //Present entry vIEw ==> NOT EXECUTED self.dismissVIEwControllerAnimated(true,completion:nil) }) logoutAlert.addAction(UIAlertAction.init(Title: "Cancel",style: .Cancel,handler: nil)) self.presentVIEwController(logoutAlert,animated: true,completion: nil)}
self.dismissVIEwControllerAnimated(true,completion:nil)行被读取,但它没有做任何事情.
解决方法 我怀疑dismissVIEwControllerAnimated没有为你做任何事情,因为视图控制器没有以模态方式呈现,而是通过导航控制器显示.要解雇是,您可以告诉导航控制器从堆栈中d出它,如下所示:logoutAlert.addAction(UIAlertAction.init(Title: "Yes",style: .Default) { (UIAlertAction) -> VoID in self.navigationController?.popVIEwControllerAnimated(true) })
不幸的是,popVIEwControllerAnimated似乎没有提供一种方法来附加你自己的完成处理程序开箱即用.如果你需要一个,你仍然可以通过利用相关的CATransaction添加一个,它看起来像这样:
logoutAlert.addAction(UIAlertAction.init(Title: "Yes",style: .Default) { (UIAlertAction) -> VoID in CATransaction.begin() CATransaction.setCompletionBlock(/* YOUR BLOCK GOES HERE */) self.navigationController?.popVIEwControllerAnimated(true) CATransaction.commit() })总结
以上是内存溢出为你收集整理的ios – 使用UIAlertAction关闭视图控制器全部内容,希望文章能够帮你解决ios – 使用UIAlertAction关闭视图控制器所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)