macOS中功能searchBar(_ searchBar: UISearchBar, textDidChange searchText: String)
的类似方法是什么?
得到了答案:
@IBOutlet weak var searchBar: NSSearchField!
func controlTextDidChange(_ obj: Notification){
let searchObject:NSSearchField? = obj.object as? NSSearchField
if searchObject==self.searchBar{
}
}
最佳答案
等效的是委托方法controlTextDidChange:notification
的对象是NSSearchfield
。你必须强制转换
@IBOutlet weak var searchBar: NSSearchField!
func controlTextDidChange(_ notification : Notification){
guard let field = notification.object as? NSSearchField, field == self.searchBar else { return }
}
关于swift - NSSearchField TextDidChange的方法是什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56512509/