ios - Xcode 8 - 当用户点击背景时让键盘消失

标签 ios xcode swift beta xcode8

我以前用过这个。

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)     
{
    self.view.endEditing(true)
}

但是现在在 Xcode 8 beta 中我得到这个错误:

声明 touchBegan(touches:withEvent) 具有与任何潜在覆盖不同的参数名称。

有什么想法吗?

最佳答案

这对我有用:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    self.view.endEditing(true)
}

请注意函数参数中非常微妙的 Swift 3 更新。在 The Swift Programming Language (Swift 3) 的第 20 和 21 页上,他们解释说:

“By default, functions use their parameter names as labels for their arguments. Write a custom argument label before the parameter name, or write _ to use no argument label.”

:)

关于ios - Xcode 8 - 当用户点击背景时让键盘消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37895032/

相关文章:

ios - XCode 失去了语法高亮的能力

ios - 线程1 : Fatal error: UnsafeMutablePointer. 初始化重叠范围

ios - Xcode 8 中的 SceneKit 地板纹理颜色已更改

ios - 为什么我的导航工具栏中的 UIBarButtonItem 不会更改标题?

ios - 自定义 View 类中的 init coder 函数出现问题

swift - 如何根据位置/与用户位置的接近程度有效地检查数据库对象?

ios - 如何在 ARKit ios 中显示网页

ios - iOS-App 中的 Facebook 时间线

swift - 是否有任何选项可以根据 uitableview 中 swift 中的屏幕宽度在 Grid 中显示 imageview

iphone - 如何最好地设置 UITableViewCell 或 UIButton 的动画以重复亮起红色