更新自定义 UITableView 单元格中的标签
Update label in custom UITableView Cell
我需要通过单击同一单元格中的按钮来更新标签。为什么我的代码不起作用?
@IBAction func actionFaveUnfave(sender: AnyObject) {
let cell = self.tableView.cellForRowAtIndexPath(sender.indexPath)
println(cell?.labelFavedTimes)
cell.labelFavedTimes = "22"}
cell.labelFavedTimes.text = "22"
cell?.labelFavedTimes.text = "22"
顺便说一句
self.tableView.cellForRowAtIndexPath(sender.indexPath)
如果单元格不可见,可以 return nil
我使用 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"
}
我需要通过单击同一单元格中的按钮来更新标签。为什么我的代码不起作用?
@IBAction func actionFaveUnfave(sender: AnyObject) {
let cell = self.tableView.cellForRowAtIndexPath(sender.indexPath)
println(cell?.labelFavedTimes)
cell.labelFavedTimes = "22"}
cell.labelFavedTimes.text = "22"
cell?.labelFavedTimes.text = "22"
顺便说一句
self.tableView.cellForRowAtIndexPath(sender.indexPath)
如果单元格不可见,可以 return nil
我使用 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"
}