ios - 从字典中删除整个元素

标签 ios swift nsdictionary

我有这样一本字典......

[

"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 相关联。因此,当我删除特定单元格时,与其关联的所有值都应该被删除。因此,如果我删除第一个单元格,那么在上面的代码片段中,所有值都来自 "113": SellerApp.Product(name: "aa... to 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 关联的所有值..?

最佳答案

@bvt,尝试像下面的代码一样删除值

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    yourArrayName.remove(at: indexPath.row)
}

希望能解决您的问题。

关于ios - 从字典中删除整个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47468663/

相关文章:

ios - 按钮角半径在 iOS 中不起作用

swift - 如何在 uiscrollview 中的按钮之间添加空间

objective-c - 停止 NSDictionary 对其项目进行排序

iphone - NSDictionary 分成两个数组(对象和键),然后按对象数组(或类似的解决方案)排序

iphone - 在 replaceScene 之后永远不会调用场景的 cocos2d dealloc

ios - swift 3 : Checking if app is in background

ios - 使用 Storyboard 重新定位 textview

ios - NSPredicate过滤关系

ios - 哪些字体可以保证在 iOS 设备上可用?

ios - 如何更改 MapView 中 MKUserLocation 注释的显示优先级?