Alexey Nakhimov
Alexey Nakhimov

Reputation: 2681

resignFirstResponder in Swift

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()
}

Upvotes: 15

Views: 11981

Answers (2)

Rajneesh071
Rajneesh071

Reputation: 31081

Try this

self.view.endEditing(true)

Upvotes: 3

Rui Peres
Rui Peres

Reputation: 25907

You could probably go with:

self.view.endEditing(true)

Upvotes: 47

Related Questions