0
我有一個UITableView與多個單元格,並在每個單元格中是一個按鈕。第一個單元格中的按鈕爲綠色,其餘爲灰色。我想設置它,以便如果用戶點擊任何灰色按鈕,第一個單元格中的按鈕變爲灰色,並且點擊的按鈕變爲綠色。無法更改UItableViewCell上的按鈕圖像點擊
@IBOutlet weak var answeredTick: UIButton!
cell.answeredTick.tag = indexPath.row
@IBAction func answerTickPressed(sender: AnyObject) {
guard let answeredTick = sender as? UIButton else { return }
if let buttonToMakeGrey = answeredTick.viewWithTag(0) as? UIButton {
buttonToMakeGrey.setImage(UIImage(named: "greyTick.png"), forState: UIControlState.Normal)
} else {
print("no success")
}
if let buttonToMakeGrey = answeredTick.viewWithTag(answeredTick.tag) as? UIButton {
buttonToMakeGrey.setImage(UIImage(named: "greenTick.png"), forState: UIControlState.Normal)
} else {
print("no success 1")
}
}
上面的問題總是無法將綠色標記更改爲灰色,並打印出「不成功」。爲什麼這個,我該如何解決它?