I'm using a UITextField and I'd like to trigger a function when the user is taping in the textfield, but I want to wait 1/4sec before triggering the function.
How can I do that ?
I'm using a UITextField and I'd like to trigger a function when the user is taping in the textfield, but I want to wait 1/4sec before triggering the function.
How can I do that ?
First, you have to create IBAction for example: changeTextField (see you screenshot)
screenshot: create an IBAction for Editing changed event
Second add this code
@IBAction func changeTextField(sender: AnyObject) {
NSObject.cancelPreviousPerformRequestsWithTarget(self, selector: #selector(ViewController.functionWithDelay), object: nil)
self.performSelector(#selector(ViewController.functionWithDelay),
withObject: nil,
afterDelay: 1/4);
}
Third, you function
func functionWithDelay() {
print("running...")
}