【问题标题】:Filtering a long list with search bar is very slow用搜索栏过滤长列表非常慢
【发布时间】:2020-10-04 15:57:00
【问题描述】:

我有一个最多包含 100 个项目的列表。在使用搜索栏过滤列表时,每个字母都需要一些时间。 如何加快搜索速度? 一种可能的解决方案是仅在单击键盘上的搜索按钮后进行过滤。

        
     
            VStack {
                SearchBar(text: $searchTerm, placeholder: "Suche")
            }
            
         
                List {
                    
                    ForEach(gesetzestextTEMPO.filter {
                        self.searchTerm.isEmpty ? true : $0.titel1.localizedCaseInsensitiveContains(searchTerm)
                            || $0.titel1.localizedCaseInsensitiveContains(searchTerm)
                            || $0.artikel.localizedCaseInsensitiveContains(searchTerm)
                            || $0.marginale.localizedCaseInsensitiveContains(searchTerm)
                            || $0.absatz0.localizedCaseInsensitiveContains(searchTerm)
                            || $0.absatz0litaz.localizedCaseInsensitiveContains(searchTerm)
                          
                        
                        })
                    { item in
                        Part13(gesetzestextTEMPO: item, searchTerm: self.$searchTerm)
                    }
                }```

【问题讨论】:

    标签: list filter swiftui searchbar


    【解决方案1】:

    尝试以下方法:

    List {
        // ...
    }
    .id(UUID())
    

    这里建议:How to fix slow List updates in SwiftUI

    【讨论】:

      猜你喜欢
      • 2017-06-27
      • 1970-01-01
      • 2021-11-13
      • 2012-01-18
      • 2021-01-13
      • 2019-06-08
      • 1970-01-01
      • 1970-01-01
      • 2022-11-12
      相关资源
      最近更新 更多