OGeek|极客世界-中国程序员成长平台

标题: ios - 转换为 swift 3.0 时在 UIButton 上使用 'dismiss()' 不明确 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 17:59
标题: ios - 转换为 swift 3.0 时在 UIButton 上使用 'dismiss()' 不明确

我在swift 2.0 中以编程方式创建了一个名为noBtn 的UIButton,它表示UIViewController 的解除。当用户单击按钮时,包含该按钮的 View Controller 将关闭。当我转换为 swift 3.0 时,我不断收到此错误:

我尝试向 dismiss() 添加参数,但没有成功。这是我没有参数的原始代码。

noBtn.addTarget(self, action: #selector(SetUpNameViewController.dismiss), for: UIControlEvents.touchUpInside)



Best Answer-推荐答案


像这样重写。首先,给同一个类一个dismiss方法:

func dismiss() {
    self.dismiss(animated:true)
}

其次,将你的 selector 改为 #selector(dismiss)

现在您的选择器将调用您的 dismiss 函数,该函数将调用 dismiss(animated:completion 这就是您要执行的操作。

关于ios - 转换为 swift 3.0 时在 UIButton 上使用 'dismiss()' 不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40444470/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4