UISearchBar检测用户何时停止键入swift [英] UISearchBar detect when user stop type in swift
本文介绍了UISearchBar检测用户何时停止键入swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现的大多数示例都在Objective - C
中,这让我很难理解,有人可以在Swift
中提供有关此问题的示例. 此处是一种解决方案,但它在Objective C
中.
Most of the example I found is in Objective - C
which is very hard for me to understand can someone provide an example regarding this question in Swift
. Here is one solution but it is in Objective C
.
推荐答案
func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
print("after every text gets changed")
timer.invalidate()
timer = NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: #selector(ViewController.output), userInfo: searchText, repeats: false)
}
func output(){
print("hello")
if timer.userInfo != nil {
print(timer.userInfo)
}
timer.invalidate()
}
这篇关于UISearchBar检测用户何时停止键入swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文