【问题标题】:Strikethrough UITableViewCell text field after cell is "complete"单元格“完成”后删除 UITableViewCell 文本字段
【发布时间】:2017-11-13 22:30:10
【问题描述】:

如何在 UIContextualAction 期间和之后删除 UITableViewCell 中的文本? (如果不能在此期间完成,只有在之后会有帮助)

Strikethrough example

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])

}

【问题讨论】:

    标签: ios arrays swift uitableview


    【解决方案1】:

    您应该将标签文本显示为属性文本。试试这个代码。未实现 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
    

    【讨论】:

    • 感谢@ahmed。我能够使用以下内容获得相应的单元格:let cell = self.dailyTable.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-26
    • 2012-08-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多