Swift 如何在tableView DidSelect上更新字典数组中特定键的值?

Swift 如何在tableView DidSelect上更新字典数组中特定键的值?,swift,xcode,uitableview,nsmutablearray,Swift,Xcode,Uitableview,Nsmutablearray,下面提到的是我的数组,我已将这些字典添加到NSMutableArray。当我点击tableView中的单元格时,我想将订单\产品\类型的值从交货更改为提货 ({ name = "Colgate Cibaca"; "order_product_type" = DELIVERY; productTotal = "30.00"; "product_id" = 32; quantity = 1; },{ name = "Lays Classic Salte

下面提到的是我的数组,我已将这些字典添加到NSMutableArray。当我点击tableView中的单元格时,我想将订单\产品\类型的值从交货更改为提货

({
    name = "Colgate Cibaca";
    "order_product_type" = DELIVERY;
    productTotal = "30.00";
    "product_id" = 32;
    quantity = 1;
},{
    name = "Lays Classic Salted";
    "order_product_type" = DELIVERY;
    productTotal = "20.00";
    "product_id" = 33;
    quantity = 1;
})
请帮助我编写代码。

它很有帮助

 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let dataObject = productArray[indexPath.row] as? NSDictionary

    DataDict = [
        "name"                     :   (dataObject?["name"] as? String)!,
        "productTotal"             :   (dataObject?["productTotal"] as? String)!,
        "quantity"                 :   (dataObject?["quantity"] as? Int)!,
        "product_id"               :   (dataObject?["product_id"] as? Int)!,
        "order_product_type"       :   "PICKUP"
    ]
    productArray.replaceObject(at: indexPath.row, with: DataDict)
    print(productArray)
}

func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
        let dataObject = productArray[indexPath.row] as? NSDictionary

        DataDict = [
            "name"                     :   (dataObject?["name"] as? String)!,
            "productTotal"             :   (dataObject?["productTotal"] as? String)!,
            "quantity"                 :   (dataObject?["quantity"] as? Int)!,
            "product_id"               :   (dataObject?["product_id"] as? Int)!,
            "order_product_type"       :   "DELIVERY"
        ]
        productArray.replaceObject(at: indexPath.row, with: DataDict)
        print(productArray)
    }
你可以试试这个 var arr=[dict1,dict2]。在didSelect中

var dictt = arr[indexpath.item] 
dictt["order_product_type"] = "picked";
arr.remove(at: indexpath.item);
arr.insert(dictt, at: indexpath.item);

你能给我们看一下你到目前为止所得到的一些代码吗?如果订单产品类型已经被接收,而不会被接收呢!我得把它捡起来!点击它之后,我现在在代码中什么也没做,我只是用arraydataObject?[name]as?中的值填充了我的tableView?一串请学习选项。别胡说八道。@EricAya你介意告诉我这里面什么是没有意义的吗?@NiravD你读过上面写的吗?我写得很清楚,这很有帮助。我回答了自己的问题。所以先读然后评论。如果不是我的答案,我会把它贴在问题上。@Rajattri从你的问题评论中,你添加了我没有尝试过的东西,然后你突然发布了答案,这就是为什么我添加了评论,我建议你不要否决你的答案,到现在为止,你说这是你正在使用的解决方案,我正在删除我的评论,正如Eric建议的那样,你需要真正了解optional@NiravD直到那个时候,我什么都没用,然后想法在脑海中不断变化,如果我在某个地方错了,那么我想你可以指导我,我需要了解什么,我在哪里缺少选择?请告诉我,以便我可以纠正它们。提前谢谢