问题描述
我有带有plist(dictionary)数据的OutlineView。我想为其添加搜索功能。我添加了一个搜索栏供用户输入。用户输入一些字符串并单击搜索按钮后,将在OutlineView中选择搜索的项目呼喊
我尝试搜索一些教程,但没有帮助。
解决方法
我发现了一些有用的教程,并且能够在outlineView中搜索字符串。
let userInput = txtSearchField.stringValue
guard let outlineView = myOutlineView else { return }
var itemIndex: Int = outlineView.row(forItem: userInput)
let value = outlineView.item(atRow: itemIndex)
if itemIndex < 0 {
//if item is not available in the outlineView
}
print("Expanding row",itemIndex)
outlineView.selectRowIndexes(IndexSet(integer: itemIndex),byExtendingSelection: .init(true))
outlineView.scrollRowToVisible(itemIndex)