你好这个问题已经提出不止一次在这里更多,但我无法找到帮助 我的问题在UICollectionViewCell 孔加入复选框时,我已经尝试了很多办法,但无济于事 此图片显示了位于UICollectionViewCell复选框在UICollectionViewCell
好吧,当我点击复选框内,这是他的选择,但食物的其余部分也被选中,这是我想做的事情,点击复选框里面的时候它在单元格中选择框并更新UICollectionView
自定义复选框代码
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
}
}
}
}
cellForItemAtIndexPath代码
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
}
是的,这就是我的意思,你可以解释更多或为我输入代码。 –
输入你的代码?不,我不打算为你做你的工作,除非你想聘请我这样做。如果您尝试实施我所描述的内容并在您遇到困难时报告回来,那么该如何? –