如何使用Swift在NSOutlineView中搜索字符串

如何使用Swift在NSOutlineView中搜索字符串

我有带有plist(dictionary)数据的OutlineView。我想为其添加搜索功能。我添加了一个搜索栏供用户输入。用户输入一些字符串并单击搜索按钮后,将在OutlineView中选择搜索的项目呼喊

我尝试搜索一些教程,但没有帮助。

iCMS 回答:如何使用Swift在NSOutlineView中搜索字符串

我发现了一些有用的教程,并且能够在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)
本文链接:https://www.f2er.com/1645548.html

大家都在问