ios – Xcode 8 – 当用户点击背景时,键盘会消失

前端之家收集整理的这篇文章主要介绍了ios – Xcode 8 – 当用户点击背景时,键盘会消失前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我过去曾经用过这个.

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.”

猜你在找的Xcode相关文章