下面提到的是我的数组,我已将这些词典添加到NSMutableArray中。当我点击tableView中的单元格时,我想将order_product_type
的值从Delivery更改为Pickup。
({
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;
})
请帮我处理代码。
答案 0 :(得分:3)
var dictt = arr[indexpath.item]
dictt["order_product_type"] = "picked";
arr.remove(at: indexpath.item);
arr.insert(dictt, at: indexpath.item);
答案 1 :(得分:0)
它有帮助
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)
}