Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
148 views
in Technique[技术] by (71.8m points)

ios - Search Bar Not Working In Collection View

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...