【问题标题】:SwiftUI macOS searchable keyboard navigationSwiftUI macOS 可搜索键盘导航
【发布时间】:2022-08-04 15:01:39
【问题描述】:

有搜索建议

        .searchable(text: $searchText, placement: .toolbar) {
            List {
                Text(\"Search suggestion 1\").searchCompletion(\"Hello\")
                Text(\"Search suggestion 2\").searchCompletion(\"Hello 2\")
            }.listStyle(.sidebar)
        }

如何在 Finder 中的建议之间启用键盘向上/向下导航

甚至鼠标选择也无济于事

?

    标签: swift macos swiftui searchable


    【解决方案1】:

    关键是使用SectionLabels 与.searchCompletion,一切都很好(键盘,完成......)

    也可以在飞行中计算结果,如图所示

        .searchable(text: $searchText, placement: .toolbar) {
            if searchText.count == 0 {
                Section("Fonts") {
                    Label("Font family A", systemImage: "textformat").searchCompletion("familyA")
                    Label("Font family B", systemImage: "textformat").searchCompletion("familyB")
                }
                Divider()
                Section("Foundries") {
                    Label("Foundry A", systemImage: "briefcase").searchCompletion("foundry:A")
                    Label("Foundry B", systemImage: "briefcase").searchCompletion("foundry:B")
                }
                Divider()
                Section("Designers") {
                    Label("Author 1", systemImage: "person").searchCompletion("author:A")
                    Label("Author 2", systemImage: "person").searchCompletion("author:B")
                }
                Divider()
                Section("Keywords") {
                    Label("Keyword 1", systemImage: "tag").searchCompletion("tag:A")
                    Label("Keyword 2", systemImage: "tag").searchCompletion("tag:B")
                }
                Divider()
                Section("Letters") {
                    Label("N", systemImage: "textformat.size.larger").searchCompletion("letter:A")
                }
            } else {
                Section("Keywords") {
                    Text("X").searchCompletion("Hello")
                }
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2015-04-15
      • 1970-01-01
      • 2022-12-02
      • 2020-05-04
      • 2022-11-29
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      相关资源
      最近更新 更多