gpt4 book ai didi

swift - 通过滑动将删除线添加到 tableview 行

转载 作者:行者123 更新时间:2023-11-28 07:48:41 28 4
gpt4 key购买 nike

我在滑动(例如向左)时在行文本上添加删除线时遇到问题。
我正在使用 tableview 方法 leadingSwipeActionsConfigurationForRowAt,但我找不到在滑动时删除删除线文本的解决方案。
截至目前,“刷过”的行实际上已被删除。

我想做什么:

Example what I want

代码:

override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let complete = completeAction(at: indexPath)
return UISwipeActionsConfiguration(actions: [complete])
}

func completeAction(at indexPath: IndexPath) -> UIContextualAction {
let action = UIContextualAction(style: .destructive, title: "Complete") { (action, view, completion) in
self.kind.remove(at: indexPath.row)
self.tableView.deleteRows(at: [indexPath], with: .fade)
completion(true)
if let context = (UIApplication.shared.delegate as? AppDelegate)?.coreDataStack.persistentContainer.viewContext {
let objectToDelete = self.fetchResultsController.object(at: indexPath)
context.delete(objectToDelete)
do {
try context.save()
} catch {
print(error.localizedDescription)
}
}
}
return action
}

最佳答案

我找到了一些解决方案。也许它可以帮助某人。这是代码:

func strikeThroughText (_ text:String) -> NSAttributedString {
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: text)
attributeString.addAttribute(NSAttributedStringKey.strikethroughStyle, value: 1, range: NSMakeRange(0, attributeString.length))
return attributeString
}

UIView.animate(withDuration: 0.1, animations: {
cell.transform = cell.transform.scaledBy(x: 1.5, y: 1.5)
}, completion: { (success) in
UIView.animate(withDuration: 0.3, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.5, options: .curveEaseOut, animations: {
cell.transform = CGAffineTransform.identity
}, completion: nil)
})

例子有一个.gif attributedText

关于swift - 通过滑动将删除线添加到 tableview 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50276214/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com