ios - Checkbox in UICollectionViewCell -
hello question has been raised more once here, can not find problem when adding checkbox in uicollectionviewcell well, i've tried lot of ways no avail image shows located in uicollectionviewcell
well, when click inside checkbox, choice, rest of foods selected, want do, click inside checkbox when selects box in cell , updated uicollectionview
custom checkbox code
var ischeckedglobal = bool() // !! global variable // might need change '= bool()' '= false' or '= true' class checkbox: uibutton { //images let checkedimage = uiimage(named: "checked") 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 } } } }
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 }
your description of want confusing.
i'm guessing want checkbox change current item. if user taps on 2nd item in list, item gets checked no others. correct?
in case don't use global.
you need maintain array of information each cell in collection view. can array of structs. array of structs , 1 property of struct boolean ischecked.
when user taps checkbox, use indexpath of current cell index array of structs , toggle ischecked boolean. in cellforitematindexpath use struct configure cell, including using ischecked boolean check/uncheck check-mark.
Comments
Post a Comment