vendredi 19 juin 2015

Checkbox in UICollectionViewCell

Hello this question has been raised more than once here, but I can not find help My problem is when adding Checkbox in UICollectionViewCell Well, I've tried a lot of ways but to no avail This image shows what is located in UICollectionViewCell

http://ift.tt/1H42eXr

Well, when I click inside the Checkbox, it is his choice, but the rest of the foods are also selected, which I want to do, click inside the Checkbox when it selects box in cell and is updated the UICollectionView

this Custom Checkbox code

    var isCheckedGlobal = Bool() // !! Global Variable // You might need to change '= Bool()' to '= false' or '= true'

class CheckBox: UIButton {

    //images

    let checkedImage = UIImage(named: "checked") as UIImage?
    let unCheckedImage = UIImage(named: "unchecked")as UIImage?


    //bool propety
    var isChecked:Bool = false{
        didSet{
            if isChecked == true{
                self.setImage(checkedImage, forState: .Normal)
            }else{
                self.setImage(unCheckedImage, forState: .Normal)
            }
        }
    }

    override func awakeFromNib() {
        self.addTarget(self, action: "buttonClicked:", forControlEvents: UIControlEvents.TouchUpInside)
        self.isChecked = false
    }

    func buttonClicked(sender:UIButton) {
        if(sender == self){
            if isChecked == true{
                isChecked = false
                isCheckedGlobal = false // !! Set variable's value
            }else{
                isChecked = true
                isCheckedGlobal = true // !! Set variable's value
            }
        }
    }

}

this is cellForItemAtIndexPath code

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


        if isCheckedGlobal == true{

            println("Checked Cell \(indexPath.row)")

        }else{

            println("unChecked Cell \(indexPath.row)")

        }




        return cell

    }




Aucun commentaire:

Enregistrer un commentaire