我需要通过单击同一单元格中的按钮来更新标签。为什么我的代码不起作用?
@IBAction func actionFaveUnfave(sender: AnyObject) {
let cell = self.tableView.cellForRowAtIndexPath(sender.indexPath)
println(cell?.labelFavedTimes)
cell.labelFavedTimes = "22"}
答案 0 :(得分:3)
cell?.labelFavedTimes.text = "22"
顺便说一句
self.tableView.cellForRowAtIndexPath(sender.indexPath)
如果单元格不可见则返回nil
答案 1 :(得分:1)
我使用superview解决了这个问题...这是我的解决方案:
let button = sender as! UIButton
let view = button.superview!
let cell = view.superview as! TableViewCellHome
let indexPath = tableView.indexPathForCell(cell)
println(indexPath)
if(indexPath != nil){
var cell = self.tableView.cellForRowAtIndexPath(indexPath!) as! TableViewCellHome
cell.labelFavedTimes.text = favedTimesInt + " Faves"
}
答案 2 :(得分:0)
cell.labelFavedTimes.text = "22"