我很困惑。在自定义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
你在哪里宣布了反应的动作 –