1

i have collectionview that contain del button and add

    cell.coupon_add.tag = indexPath.row
    cell.coupon_add?.layer.setValue(id, forKey: "coupon_id")
    cell.coupon_add?.layer.setValue(uID, forKey: "user_id")
    cell.coupon_add?.addTarget(self, action: #selector(ViewController.addItem(_:)), forControlEvents: UIControlEvents.TouchUpInside)

  func addItem(sender:UIButton) {
    let point : CGPoint = sender.convertPoint(CGPointZero, toView:collectionview)
    let indexPath = collectionview!.indexPathForItemAtPoint(point)
    let cell = collectionview.dequeueReusableCellWithReuseIdentifier("listcell", forIndexPath: indexPath!) as! ListCell

    let coupon_id : String = (sender.layer.valueForKey("coupon_id")) as! String
    let user_id : String = (sender.layer.valueForKey("user_id")) as! String
        if user_id == "empty" {
            self.login()
        }else{
            print("adding item**",indexPath)

            cell.coupon_add.hidden = true
            cell.coupon_del.hidden = true
            let buttonRow = sender.tag
            print(buttonRow)
        }
}

i want to hide the add button when trigger. i just get the value of the indexPath but i dont know how to hide it without refresh the collectionview

Mavs Mavs
  • 409
  • 1
  • 4
  • 10

1 Answers1

0

Create a custom cell

class CustomCell: UICollectionViewCell {

    @IBOutlet weak var label: UILabel!
    @IBOutlet weak var delButton: UIButton!
    @IBOutlet weak var addButton: UIButton!

    @IBAction func addTapped(sender: AnyObject) {
       delButton.removeFromSuperview()
       addButton.removeFromSuperview()
    }
}

Typical CollectionView Controller

class ViewController: UICollectionViewController {

    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 10;
    }

    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CustomCell

        cell.label.text = "Cell \(indexPath.row)"

        return cell
    }

}

And your button will gone, when you hit them

Bagus Cahyono
  • 668
  • 2
  • 8
  • 17