Ich bevölke meine tableView
mit OrderDetailsArray
. Dann auf DidSelect
bin ich Mehrwert zu reorderArray
hinzufügen. Wie entferne ich den Wert vom Array beim Tippen auf DidDeSelect
?So entfernen Sie den Wert im Feld Array of Dictionary on Wurde DeSelect ausgewählt?
Mein Tableview Delegat 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 ist NSMutableArray()
können Sie versuchen, den Code 'reorderArray.removeObjects platzieren (bei: Indizes) cell.contentView.backgroundColor = UIColor.clear print (reorderArray)' innerhalb Schließung – Priyal
Es kann nicht getan werden, weil Schließung Wert zurückgibt, also wenn ich so tue, erhalte ich einen Fehler: Variable, die innerhalb seines eigenen Anfangswerts benutzt wird –