加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 18:07:16 所属栏目:百科 来源:网络整理
导读:我过去曾经用过这个. override func touchesBegan(touches: SetUITouch,withEvent event: UIEvent?) { self.view.endEditing(true)} 但现在在Xcode 8 beta中我收到此错误: 声明touchBegan(touches:withEvent)具有来自任何潜在覆盖的不同参数名称. 有什么想
我过去曾经用过这个.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读