gpt4 book ai didi

ios - 删除收藏的单元格

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

伙计们,我在删除单元格时遇到了问题。

首先,我在每个单元格上添加了一个自定义 UIButton,当执行该按钮时,它会将项目保存在 UserDefaults 中,并显示为绘制的心形图像,我在另一个 Controller 中获取保存的项目,但是当我删除该项目时,UIButton 图像保持不变。我不知道如何将按钮设置为默认状态(图像)。

首先我创建了自定义 UIButton

lazy var favoriteButton: UIButton = {
let button = UIButton(type: .system)
button.addTarget(self, action: #selector(handleTapped), for: .touchUpInside)
button.setImage(#imageLiteral(resourceName: "herzfavorie").withRenderingMode(.alwaysTemplate), for: .normal)
button.tintColor = .white
return button
}()

这个 btn 选择器“handleTapped”将项目保存在用户默认值中并制作动画

let key = "key"



@objc func handleTapped() {

guard let product = self.product else { return }

let data = NSKeyedArchiver.archivedData(withRootObject: listOfPodcasts)
UserDefaults.standard.set(data, forKey: key)

var listOfPodcasts = Product.savedProducts()

listOfPodcasts.append(product)

self.showHeartLiked()


}

that saves the item in User Defaults and creates this effect on cell但后来当我删除这个功能中的产品时

override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {


let removalProduct = savedProducts[indexPath.row]

let tableViewAction = UITableViewRowAction(style: .default, title: "Delete") { (_, _) in

self.savedProducts.remove(at: indexPath.row)
self.tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.automatic)

Product.deleteProducts(product: removalProduct)

}在这个功能按钮之后应该是默认的

button should be as by default

但是默认情况下按钮不会保留我希望当有人知道如何在删除后将按钮恢复为默认状态时我能解释清楚我将不胜感激

最佳答案

使用 ListView Controller 中的 NotificationCenter 来提醒其他 View Controller 更改按钮样式。

关于ios - 删除收藏的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53924876/

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