简体   繁体   English

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

[英]How to search string in NSOutlineView using Swift

plist数据 I have OutlineView with plist(dictionary) data.我有带有 plist(字典)数据的 OutlineView。 I want to add search functionality to it.我想给它添加搜索功能。 I have added a search-bar for user input.我为用户输入添加了一个搜索栏。 Once user enter some string and click on search button, searched item shout get selected in the OutlineView一旦用户输入一些字符串并单击搜索按钮,搜索的项目就会在 OutlineView 中被选中

I tried searching for some tutorials but no help.我尝试搜索一些教程但没有帮助。

I have found some helpful tutorials and able to search string in the 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM