resignFirstResponder in Swift

痞子三分冷 提交于 2019-12-22 03:21:44

问题


How can I implement it in the new language of Apple:

Objective-C code:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        for (UIView *view in self.view.subviews)
        [view resignFirstResponder];
}

I have tried to do so. But the keyboard does not disappear:

Swift code:

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    super.touchesBegan(touches, withEvent: event)
    self.view.resignFirstResponder()
}

回答1:


You could probably go with:

self.view.endEditing(true)



回答2:


Try this

self.view.endEditing(true)


来源:https://stackoverflow.com/questions/24034786/resignfirstresponder-in-swift

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