【发布时间】:2017-11-24 07:53:44
【问题描述】:
我有一本这样的字典...
[
"113": SellerApp.Product(name: "aaaa", id: "113", images: [SellerApp.ProductImage(myId: "996", url: http://myApp.com/public/uploads/products/123_113_1_image_123456789, isDefault: true)], theRate: "234", quantity: "17", sku: "Hdjsu", prdCateg: "tr123", prodDescr: "Gdhd", mrp: "520"),
"101": SellerApp.Product(name: "dfg", id: "101", images: [SellerApp.ProductImage(myId: "982", url: http://myApp.com/public/uploads/products/563_101_1_image_1011121314, isDefault: true)], theRate: "123", quantity: "7", sku: "345", prdCateg: "tr123", prodDescr: "Test", mrp: "234")
]
现在这些值中的每一个都与一个 tableviewcell 相关联。因此,当我删除特定单元格时,与其关联的所有值都应该被删除。因此,如果我删除第一个单元格,那么在上面的 sn-p 中,从 "113": SellerApp.Product(name: "aa... 到 mrp: "520") 的所有值都应该被删除。
我尝试过这样的事情......
for (index, dict) in self.appDelegate.myDictionary1.enumerated() {
if dict.key == (self.appDelegate.commonArrForselectedItems[indexPath.section].id) {
self.appDelegate.myDictionary1.removeValue(forKey: self.appDelegate.commonArrForselectedItems[indexPath.section].id)
}
}
但这似乎会删除 id 本身,并且所有剩余的值都会保留下来。如何从字典中删除与此 ID 关联的所有值..?
【问题讨论】:
-
为什么在点击索引时不删除tableView的didSelectIndexPath方法中的值?
-
我的删除方式似乎有些问题......
标签: ios swift nsdictionary