【发布时间】:2016-08-29 09:52:38
【问题描述】:
当另一个Cell Button 被选中时,我想将之前选择的Cell Button 图像更改为其默认状态。
默认状态sender.selected = false未选择按钮时
按下按钮后sender.selected = true
func collectionView(collectionView: UICollectionView,
cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(
reuseIdentifier, forIndexPath: indexPath) as! RadioCollectionViewCell
cell.btnPlay.addTarget(self,
action: Selector("audioControlButtonAction:"),
forControlEvents: UIControlEvents.TouchUpInside)
cell.btnPlay.tag = indexPath.row
return cell
}
func audioControlButtonAction(sender: UIButton) {
if sender.selected == false {
sender.selected = true
} else {
sender.selected = false
}
}
谁能告诉我如何做到这一点? 谢谢
【问题讨论】:
-
在更改按钮的选定状态之前,您是否尝试过
self.collectionView.reloadData()? -
是的,但它不能正常工作,当我按下单元格按钮时它会自动更改另一个按钮图像?
-
很简单,您可以将索引值保存在 didselect 上,而不是重新加载并检查 cellForItemAtIndexPath 上的索引。
-
对我不起作用,请检查我的代码吗?因为 didselect 方法只在单元格上起作用,而不是在单元格按钮上?
-
感谢您帮助我(y)
标签: ios swift ios7 uicollectionview