The search bar in the weekly view controller in my app isn't working. When I tap the bar the collection view cells disappear. Im not sure why this happened. Below is the code.
Project link:https://github.com/lexypaul13/Trending-Tv-Shows
var shows : [Show] = []
var dataSource: UICollectionViewDiffableDataSource<Section,Show>!
var filteredShows : [Show] = []
func updateData(shows:[Show]){ //shows follwers
var snapshot = NSDiffableDataSourceSnapshot<Section,Show>()
snapshot.appendSections([.main])
snapshot.appendItems(shows)
DispatchQueue.main.async {
self.dataSource.apply(snapshot,animatingDifferences: true)
}
}
extension WeeklyViewController: UISearchResultsUpdating{
func updateSearchResults(for searchController: UISearchController) {
guard let filter = searchController.searchBar.text, filter.isEmpty else {
return
}
isSearching = true
filteredShows = shows.filter { ($0.unwrappedName.lowercased().contains(filter.lowercased())) }
updateData(shows: filteredShows)
}
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
isSearching = false
updateData(shows: filteredShows)
}
}
question from:
https://stackoverflow.com/questions/65897258/search-bar-not-working-in-collection-view 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…