嗯,我知道这些类型的问题是由SO之前回答的,但我的有点不同,所以请阅读它。UIButton tableview cell change text
我在tableview单元格内使用了一个按钮。点击按钮我显示一个AlertViewController的动作列表。在选择动作我的按钮文本和我的自定义模型类propery被改变。
按钮点击按钮文字正在改变。但我的问题是单元格不存储按钮状态。如果我更改第一个单元格的按钮,然后单击第二个单元格按钮将所有其他按钮恢复为其默认文本。
这里是我的代码
设置单元格数据
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("dbColumns", forIndexPath: indexPath) as! CustomColumnTableViewCell
let column = columns[indexPath.row]
cell.dbColumnName.text = column.name
cell.dbColumnOrder.titleLabel?.text = column.order
cell.dbColumnOrder.tag = indexPath.row
print(columns)
cell.dbColumnOrder.addTarget(self, action: #selector(ViewController.showAlert(_:)), forControlEvents: UIControlEvents.TouchUpInside)
return cell
}
按钮操作点击
//MARK:Show Alert
func showAlert(sender:UIButton){
let alert = UIAlertController(title: "Column Order", message: "Please select column order", preferredStyle: .ActionSheet)
let index = sender.tag
let indexPath = NSIndexPath(forRow: index, inSection: 0)
alert.addAction(UIAlertAction(title: "None", style: .Default, handler: { (action) in
//execute some code when this option is selected
self.columns[index].order = "None"
self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .None)
}))
alert.addAction(UIAlertAction(title: "Assending", style: .Default, handler: { (action) in
//execute some code when this option is selected
self.columns[index].order = "Assending"
self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .None)
}))
alert.addAction(UIAlertAction(title: "Desending", style: .Default, handler: { (action) in
//execute some code when this option is selected
self.columns[index].order = "Desending"
self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .None)
}))
self.presentViewController(alert, animated: true, completion: nil)
}
请麻我。
你可能会显示什么是截图或GIF的确切问题?我很难明白可能是什么问题。 – dirtydanee
@dirtydanee我添加了一个链接,请访问它 –