title: Searchbar not refreshing UIbutton color
body: <p>Here is my headache... Hope someone has the medecine.</p>
  
  <p>The situation
  - I have a searchbar linked to a tableview just below
  - Tableview cell is made of 1 label and 1 button
  - The button is a "favorite" button linked to coredata
  - If the text of the label does exist in coredata, its color is brown
  - If the text does not exist in coredata, its color is grey. If it is pressed, it turns to brown, and the text of the lable is registered in coredata</p>
  
  <p>The headache
  - Everything is works perfectly for the first filtering (everything is in place, buttons colors appear correctly wether the text is registered ir not, and registering by clicking on the button works perfectly fine BUT...
  - when the search changes, cells are perfectly (un)filtered but not the button: those who should appear ingrey appear in brown
  - If I change screen and come back everything is reset and buttons colors are OK</p>
  
  <p>I can't find out how to refresh the button's title color during the search. Buttons' title is text. Any hint?</p>
  
  <p>Code in CellForRowAt</p>
  
  <pre><code>    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
      let cell = searchTbv.dequeueReusableCell(withIdentifier: "searchCell", for: indexPath) as! SearchTbvCell
  
      if searhing {
          cell.searchLbl.text = mySearch[indexPath.row]
      }
      else {
          cell.searchLbl.text = dataSearch.searchItem[indexPath.row]
      }
  
      return cell
  }
  </code></pre>
  
  <p>Code for the search bar</p>
  
  <pre><code>extension SearchVC: UISearchBarDelegate {
  
  func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
  
      searhing = true
  
      mySearch = dataSearch.searchItem.filter({$0.lowercased().folding(options: .diacriticInsensitive, locale: .current).prefix(searchText.count) == searchText.lowercased()})
  
      searchTbv.reloadData()
  
  }
  
  func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
      searhing = false
      searchBar.text = ""
      searchTbv.reloadData()
  
  }
  </code></pre>
  
  <p>Code to set button color (code located in the custom cell class):</p>
  
  <pre><code>class SearchTbvCell: UITableViewCell {
  
  //MARK: OUTLETS
  @IBOutlet weak var searchLbl: UILabel!
  @IBOutlet weak var searchBtn: UIButton!
  
  override func awakeFromNib() {
      super.awakeFromNib()
      fetchFromCoreData()
  }
  
  override func setSelected(_ selected: Bool, animated: Bool) {
      super.setSelected(selected, animated: animated)
      fetchFromCoreData()
  }
  
  
  @IBAction func favoriteBtnTapped(_ sender: UIButton) {
  
      // Set fav button color to brown if selected/tapped
      searchBtn.setTitleColor(.brown, for: .normal)
  
      // Permanently record selection as favorite into coredata
      recordPermanently()
  }
  
  
  
  //MARK: METHODS
  
  // Fetch contents from CoreData and up-date button's color consequently
  func fetchFromCoreData () {
      // Create a reference to container
      let appDelegate = UIApplication.shared.delegate as? AppDelegate
      // Create a context from the container
      let managedContext = appDelegate?.persistentContainer.viewContext
      // Prepare a request and sorting
      let myRequest = NSFetchRequest&lt;NSFetchRequestResult&gt;(entityName: "MyFavorites")
      myRequest.predicate = NSPredicate(format:"favoriteWines = %@", searchLbl.text!)
      do {
          let results = (try managedContext?.fetch(myRequest))!
          for _ in results {
              searchBtn.setTitleColor(.brown, for: .normal)
          }
      }
      catch{}
  }
  
  
  // Record permanently in core data and changethe button's color
  func recordPermanently(){
      // Create a reference to container
      guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {return}
      // Create a context from the container
      let managedContext = appDelegate.persistentContainer.viewContext
      // Create an entity to manage records
      let recordEntity = NSEntityDescription.entity(forEntityName: "MyFavorites", in: managedContext)!
      // Create a new record
      let newRecord = NSManagedObject(entity: recordEntity, insertInto: managedContext)
      // Pass values to new record
      newRecord.setValue(searchLbl.text!, forKeyPath: "favoriteWines")
      // Save record
      do {
          try managedContext.save()
          searchBtn.setTitleColor(.brown, for: .normal)
      }
      catch let error as NSError{
          print("Failed to save permanently. \(error), \(error.userInfo)" )
      }
  }
  </code></pre>
  
  <p>}</p>