ios - 如何使用完成处理程序正确关闭模态视图 Controller

标签 ios swift uiviewcontroller

我有 viewController1viewController2,它们是模态呈现的,我想在关闭第二个时使用完成处理程序,但我无法实现。我认为我必须编写一个函数并将其放在那里:

viewController.dismissViewControllerAnimated(true, completion: funcToCall())

但是我得到了这个错误:

Cannot convert value of type '()' to expected argument type '(() -> Void)?'

谁能给我解释一下,我怎样才能正确执行完成处理程序?

最佳答案

非常简单,将 funcToCall() 作为 completion 参数传递(重要说明 - 我在这里使用大括号):

viewController.dismissViewControllerAnimated(true, completion: { 
    funcToCall()
})

完成参数文档:

The block to execute after the view controller is dismissed. This block has no return value and takes no parameters. You may specify nil for this parameter.

关于ios - 如何使用完成处理程序正确关闭模态视图 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38595633/

相关文章:

ios - 以编程方式调用 iOS 应用程序扩展

ios - swift : Pass TableViewCell text to new ViewController's cell

ios - 绝对值函数 abs() 在 Swift 3.0 中不可用。使用 abs(_ :) free function?

uiviewcontroller - 横向自定义 UIViewController 动画的解决方法?

ios - 使用容器 View Controller 和 Storyboard 构建滑出式菜单。我很困惑

ios - iOS 7 中的媒体查询不起作用

ios - 从服务器监听 iCal 事件变化

ios - 从应用程序中删除了核心位置但仍被要求提供用户位置

ios - 并非在所有情况下都调用 Swift BLE 函数 didConnectPeripheral

ios - 将类与 Root View Controller 连接(UINavigationController)