【发布时间】:2019-08-16 02:17:01
【问题描述】:
我下面的代码通过删除按钮从索引中删除了一个字符串。但是,它不会从核心数据集中删除。如果刷新视图,集合中的所有项目仍然存在。我想要的只是当用户点击删除函数时,该字符串将被永久删除。这是我的代码https://www.dropbox.com/s/m5fpiilksye4pru/photo2.zip?dl=0的下载链接
var users = [Item]()
class cell: UICollectionViewCell {
var delegateA: datacollectionProfotocol?
var index : IndexPath?
@IBOutlet var name : UILabel!
@IBAction func show() {
}
@IBAction func delete() {
delegateA?.deleteData(indx: (index?.row)!)
}
}
protocol datacollectionProfotocol {
func deleteData(indx:Int)
}
extension ViewController : datacollectionProfotocol {
func deleteData(indx: Int) {
users.remove(at: indx)
block.reloadData()
}
【问题讨论】:
-
你能解释一下这行我想要的是当用户点击删除函数时,该字符串将被永久删除
-
当我点击删除按钮时,它不会从索引中删除该项目,它只会隐藏它。当我刷新视图时,该项目仍然存在。所以说 set = {a,e,c}。我删除了 e 集合应该只是 {a,c}。现在我的代码没有删除 e。
-
你的示例代码在我的 mac 上不起作用
标签: swift core-data uicollectionview protocols uicollectionviewcell