【发布时间】:2014-06-04 10:16:39
【问题描述】:
如何用 Apple 的新语言实现它:
Objective-C 代码:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UIView *view in self.view.subviews)
[view resignFirstResponder];
}
我已经尝试过这样做。但是键盘并没有消失:
Swift 代码:
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
self.view.resignFirstResponder()
}
【问题讨论】:
-
你的 objc 和 Swift 代码做不同的事情。您是否尝试移植有效的 Objective-C 实现?
-
方法签名现在重写 func touchesBegan(touches: Set
, withEvent event: UIEvent)