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

问题描述

plist data

我有带有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)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...