我很困惑。在自定義UITableViewCell中訪問UIButton
在我的cellForRowAtIndexPath方法,我想設置一個UIButton標題:
不工作:
cell?.react?.setTitle("\(currentObject.likes)", forState: UIControlState.Normal)
其中react
是一個UIButton,那是我的UITableViewCell子類的子視圖。
我似乎無法更新我的UIButton的標題。我發現修改它的唯一方法是通過UITapGestureRecognizer在我的UITableViewCell子類,
工作:
func reaction(button : UIButton) {
if button.imageView?.image == UIImage(named: "ic_favorite.png") {
button.setImage(UIImage(named: "ic_favorite_border.png"), forState: UIControlState.Normal)
} else {
button.setImage(UIImage(named: "ic_favorite.png"), forState: UIControlState.Normal)
}
}
是'react'是你的按鈕?你爲什麼寫'反應是我定製細胞的一個子類?'? – Tj3n
你在哪裏宣佈了反應的動作 –