ios - UISearchBar 检测用户何时停止输入 swift

标签 ios swift uisearchbar

我发现的大部分示例都在 Objective - C 中,这对我来说很难理解,有人可以在 Swift 中提供有关此问题的示例。 Here是一种解决方案,但它在 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()
}

关于ios - UISearchBar 检测用户何时停止输入 swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41059449/

相关文章:

ios - 当应用程序在后台时,如何播放项目中本地添加的 mp3 文件?

uitableview - 使用swift3在tableview中搜索栏和部分

iphone - 是否可以更改 UISearchDisplayController 搜索栏的边框颜色?

ios - 如何在iOS的AWS Lambda中发送请求 header 数据

ios - 如何捕获自动布局约束冗余

ios - Swift 4 Alamofire 分段上传不起作用

swift - SwiftLint 的开关大小写格式问题

ios - 如何将谷歌即时搜索栏添加到 iOS 应用程序

ios - 如何在我的通用应用程序中的每台设备的角落放置一个硬币标签?

objective-c - 如何在 iOS 中存储中小型数据集(以便于 iCloud 同步)?