I'm trying to hide my keyboard when a button is pressed. I'm using GCD to simultaneously fetch NSData from a server and show an animation.
The problem is, whenever I press the button the keyboard stays active. I've tried putting the _self.view.endEditing(true) into the GCD function but with no success.
I would greatly appreciate if you would help me with this.
@IBAction func tragi(sender: UIButton) {
dispatch_async(dispatch_get_main_queue()) { [weak self] in
if let _self = self {
SwiftSpinner.show("Fetching data.....")
_self.parseJSON2 { (makeModel) in
print("print this")
}
}}
}
yourtextField.resignFirstResponder()