你好這個問題已經提出不止一次在這裏更多,但我無法找到幫助 我的問題在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
}
是的,這就是我的意思,你可以解釋更多或爲我輸入代碼。 –
輸入你的代碼?不,我不打算爲你做你的工作,除非你想聘請我這樣做。如果您嘗試實施我所描述的內容並在您遇到困難時報告回來,那麼該如何? –