UISearchBar检测用户何时停止键入swift [英] UISearchBar detect when user stop type in swift

查看:92
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆