当另一个单元格按钮被选中时,将之前的单元格按钮图像设置为默认状态
Set previously Cell Button image to its default state when another cell button is selected
我想将之前 selected Cell Button
图像更改为默认状态,而另一个 Cell Button
是 select。
默认状态 sender.selected = false
当按钮未 selected
按下按钮后 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
}
}
我想将之前 selected Cell Button
图像更改为默认状态,而另一个 Cell Button
是 select。
默认状态 sender.selected = false
当按钮未 selected
按下按钮后 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
}
}