如何在UIContextualAction期间和之后删除UITableViewCell中的文本? (如果不能在期间完成,之后才会有所帮助)
func tableView(_ tableView: UITableView,
leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
{
let doneAction = UIContextualAction(style: .normal, title: "DONE", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
print("Done left")
self.dailyTasks.append("\(self.dailyTasks[indexPath.row])")
self.dailyTasks.remove(at: indexPath.row)
UserDefaults.standard.set(self.dailyTasks, forKey: "dailyTasks")
self.dailyTable.reloadData()
success(true)
})
doneAction.backgroundColor = .darkGray
return UISwipeActionsConfiguration(actions: [doneAction])
}
答案 0 :(得分:0)
您应该将标签文本显示为attributiontext。试试这个代码。未实现getRespectiveCell方法。使用您自己的逻辑来获取该索引路径的相应单元格
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: "Your Text")
attributeString.addAttribute(NSStrikethroughStyleAttributeName, value: 2, range: NSMakeRange(0, attributeString.length))
let cell = getRespectiveCell(indexPath.row)
cell.textLabel.attributedText = attributeString