我有一种情况,我有功能说
func openViewController(completion:(success:Bool) -> Void)
{
//code here to present some view controller name MYVC
self.presentViewController(myVC, animated: true, completion: {
})
}
在我调用上述 openViewController 方法的同一类中的以下函数中,我在委托(delegate)的帮助下从 MYVC 得到回调
func handleDismissOfVC(){
self.dismissViewControllerAnimated(true, completion:{
})
}
现在我面临的挑战是,当我使用handleDimissOfVC()关闭 View Controller 时,调用具有成功标志的openViewController的完成 block 。我怎样才能实现这个目标?
最佳答案
您需要创建一个实例变量来保存闭包。在 openViewController 中,将闭包保存到该实例变量中。
在您的handleDismissOfVC函数中,调用保存到实例变量的 block 。
关于ios - swift:如何从两个单独的方法执行相同的闭包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35633214/