self.navigationController?.popViewControllerAnimated from UIAlertController

半腔热情 提交于 2019-12-05 04:21:27

Just add an explicit return statement in the closure body:

alertController.addAction(UIAlertAction(title: "Ok", style: .Default, handler: { action in
    self.navigationController?.popViewControllerAnimated(true)
    return
}))

The reason why that happens is that a single statement closure is handled as the return value, so the compiler uses the return value of popViewControllerAnimated, which unsurprisingly is a UIViewController?. The explicit return statement avoids that.

This behavior is documented in Implicit Returns from Single-Expression Closures

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!