iOS:使用UIModalPresentationStyle.OverCurrentContext时检测dismissViewControllerAnimated

iOS:使用UIModalPresentationStyle.OverCurrentContext时检测dismissViewControllerAnimated,ios,swift,uiviewcontroller,uimodalpresentationstyle,Ios,Swift,Uiviewcontroller,Uimodalpresentationstyle,在我的ViewControllerA中,我尝试通过调用以下命令来显示ViewControllerB: let VC2 = ViewControllerB() VC2.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext presentViewController(VC2, animated: true, completion: nil) 因此,ViewControllerB的内容显示在ViewControlle

在我的ViewControllerA中,我尝试通过调用以下命令来显示ViewControllerB

let VC2 = ViewControllerB()
VC2.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
presentViewController(VC2, animated: true, completion: nil)
因此,ViewControllerB的内容显示在ViewControllerA的顶部

按下视图控制器B中的按钮时,这称为:

dismissViewControllerAnimated(true, completion: nil)
但是,
viewwillbeen
ofViewControllerA不会被调用

如果删除了行
VC2.modalPresentationStyle=uimodalPresentStyle.OverCurrentContext
,则调用ViewControllerA的
视图


在使用
UIModalPresentationStyle.OverCurrentContext时,
视图将显示视图控件的
,而不调用。在这种情况下,如何检测ViewControllerB是否在ViewControllerA中被解除?我想在ViewControllerA中运行一些代码,但不想在ViewControllerB中使用
completion
dismissViewControllerAnimated
,为什么不在
ViewControllerB
上创建自己的完成块呢?您可以在
ViewControllerA
上创建
ViewControllerB
实例时分配它,然后在
ViewControllerB
上调用
dismissViewControllerAnimated
时调用它,谢谢您的回答。不幸的是,我不熟悉完成块。我花了几个小时在网上搜索,但还是不知道该怎么办。你能给我举个例子或一些提示吗?非常感谢!这里有很多答案可以帮助你:)喜欢或者感谢你在Objective-C中的链接。它们帮助我理解了完成模块。现在我在Swift中找到了一个解决方案。还有一些参考资料。@ehhhuang不客气!很高兴你的问题解决了。愿意接受我的回答吗?你的回答对我很有帮助。我刚刚了解了SO中“接受答案”的含义。:)