Skip to content

Commit

Permalink
search bar bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
grenos committed Apr 13, 2020
1 parent cb76820 commit 5e64bca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
Binary file not shown.
20 changes: 7 additions & 13 deletions GHFollowers/Screens/FollowerListVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ class FollowerListVC: GFDataLoadingVC {

// set the delegate for searchResultsUpdater
searchController.searchResultsUpdater = self
// set the delegate to listen to the search bar events (needed for the cancel button)
searchController.searchBar.delegate = self
searchController.searchBar.placeholder = "Search followers"
// set overlay to false so we can tap on a user
searchController.obscuresBackgroundDuringPresentation = false
Expand Down Expand Up @@ -287,12 +285,17 @@ extension FollowerListVC: UICollectionViewDelegate {


// MARK: Filter arrays
extension FollowerListVC: UISearchResultsUpdating, UISearchBarDelegate {
extension FollowerListVC: UISearchResultsUpdating {

// this informs the VC every time the search results are changed
func updateSearchResults(for searchController: UISearchController) {

guard let filter = searchController.searchBar.text, !filter.isEmpty else {return}
guard let filter = searchController.searchBar.text, !filter.isEmpty else {
filteredFollowers.removeAll()
updateData(on: followers)
isSearching = false
return
}

//set the switch on
isSearching = true
Expand All @@ -307,15 +310,6 @@ extension FollowerListVC: UISearchResultsUpdating, UISearchBarDelegate {
// Update collection view with new results passing the new array
updateData(on: filteredFollowers)
}


// when cancel button is tapped update the collection View using the original follwers array
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
//set the switch on
isSearching = false

updateData(on: followers)
}
}


Expand Down

0 comments on commit 5e64bca

Please sign in to comment.