我正在使用OrderDetailsArray
填充我的tableView
。然後在DidSelect
我爲reorderArray
增值。 如何從輕敲DidDeSelect
的陣列中刪除值?如何刪除Did DeSelect字典數組中的值?
我的tableView委託funcs中:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let object = orderDetailsArray.object(at: (indexPath as NSIndexPath).row) as! NSDictionary
let storeID = UserDefaults.standard.value(forKey: DefaultsKey.storeID.rawValue) as! Int
let barcode = object["barcode"] as! String
let mrp = object["mrp"] as! String
let productDiscount = object["product_discount"] as! String
reorderDictionary.setObject((storeID), forKey: "store_id" as NSCopying)
reorderDictionary.setObject((barcode), forKey: "barcode" as NSCopying)
reorderDictionary.setObject((mrp), forKey: "mrp" as NSCopying)
reorderDictionary.setObject((productDiscount), forKey: "product_discount" as NSCopying)
reorderArray.add(reorderDictionary)
let cell = tableView.cellForRow(at: indexPath) as! OrderHistoryProductDetailsTableViewCell
cell.contentView.backgroundColor = UIColor.red
print(reorderArray)
}
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath) as! OrderHistoryProductDetailsTableViewCell
let object = reorderArray.object(at: (indexPath as NSIndexPath).row) as! NSDictionary
reorderArray.remove(object)
cell.contentView.backgroundColor = UIColor.clear
print(reorderArray)
}
reorderArray是NSMutableArray()
可以嘗試配股代碼'reorderArray.removeObjects(在:索引) cell.contentView.backgroundColor = UIColor.clear 打印(reorderArray)'內關閉 – Priyal
它不能完成,因爲閉包返回值,所以如果我這樣做,那麼我得到一個錯誤:在它自己的初始值內使用的變量 –