title: Hiding button on a particular tableview cell
body: <p><strong>Background:</strong></p>
  
  <p>My code displays a list of food items in a <code>tableview</code>, and in a <code>UITableViewCell</code> there is a <code>button</code> to add the food items to cart as needed. 
  When a particular item is added to cart, the add <code>button</code> corresponding to that <code>cell</code> should be hidden and rest all which are not added should not be hidden.</p>
  
  <p><strong>Problem:</strong></p>
  
  <p>The problem is, when I add an item say which is at <code>index: 0</code> to cart, it gets added successfully and <code>button</code> is hidden, but when I click on second <code>button</code> which is at <code>index : 1</code>, second item also gets added to cart but the first item button becomes unhidden, at a time only one button which is at the current index is getting hidden instead of all the item buttons which are added to cart.</p>
  
  <pre><code>   func addToCart(_ button : UIButton) {
          self.selectedIndex = button.tag            
          let foodItem : HCFoodItem = arrFoodItems?.object(at: self.selectedIndex) as! HCFoodItem
          foodItem.isFoodAddedToCart = true
          arrItemsAddedToCart?.add(foodItem)
          let arrayCount  = arrItemsAddedToCart?.count
          let badgeCount : String = String(format: "%d", arrayCount!)
          tabBarController?.tabBar.items?.last?.badgeValue = badgeCount
          HCDataCache.sharedDataCacheInstance.cacheData(object: arrItemsAddedToCart, key: HC_CACHE_KEY_CART_ITEM)
          self.foodItemsTableView?.reloadData()
  
      }
  
   // hide/unhide buttons here...
  
   override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let cellId: NSString = "LazyLoadTableViewCell"
  
          var foodItems : HCFoodItem?
          foodItems = arrFoodItems?.object(at: indexPath.row) as! HCFoodItem?
          let cell: HCFoodItemTableViewCell = tableView.dequeueReusableCell(withIdentifier: cellId as String)! as! HCFoodItemTableViewCell
  
          cell.imgFood?.downloadImageFrom(link: foodItems?.strFoodImage as! String, contentMode: UIViewContentMode.scaleAspectFill)
  
          cell.btnAddDelete?.tag = indexPath.row
          cell.btnAddDelete?.addTarget(self, action: #selector(HCHomeViewController.addToCart(_:)), for: UIControlEvents.touchUpInside)
  
          let itemsAddedToCart : NSMutableArray? = HCDataCache.sharedDataCacheInstance.fetchCachedDataForKey(key: HC_CACHE_KEY_CART_ITEM)
  
          if (itemsAddedToCart?.count)! &gt; 0 {
              for cardFoodItem in itemsAddedToCart!{
                  let  foodItem : HCFoodItem = cardFoodItem as! HCFoodItem
                  if foodItem.strFoodName == foodItems?.strFoodName {
                      cell.btnAddDelete?.isHidden = true
                  }else{
                      cell.btnAddDelete?.isHidden = false
                  }
  
  
              }
          } else {
              cell.btnAddDelete?.isHidden = false
          }            
          cell.selectionStyle = .none    
          return cell  
      }
  </code></pre>