gpt4 book ai didi

ios - 当另一个单元格按钮被选中时,将之前的单元格按钮图像设置为默认状态

转载 作者:搜寻专家 更新时间:2023-11-01 06:19:24 25 4
gpt4 key购买 nike

我想在选择另一个 Cell Button 时将先前选择的 Cell Button 图像更改为默认状态。

默认状态 sender.selected = false 当 Button 未被选中时

按下按钮后 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
}
}

谁能告诉我我该怎么做?谢谢

最佳答案

var selectIndex:Int = -1

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+1

return cell
}

func audioControlButtonAction(sender: UIButton)
{
if selectIndex != -1 && selectIndex != sender.tag
{
let bt:UIButton = self.view.viewWithTag(selectIndex) as! UIButton
if bt.selected == true
{
bt.selected = false
}
}

if sender.selected == false
{
sender.selected = true
selectIndex = sender.tag
}
else
{
sender.selected = false
selectIndex = -1
}
}

关于ios - 当另一个单元格按钮被选中时,将之前的单元格按钮图像设置为默认状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37019598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com