我的应用程序中有一个对象数组,它传递给另一个名为 restaurantViewController 的 VC,该值存储在 restMenu 中,现在的问题是,每当我滚动 UITableView 时,ItemQuantityCell 值总是被重用为 0,这是我的 restMenu 中的默认值如何更新我的 restMenu 中的值,以便我可以将它传递给 checkoutVC,并为我的 ItemQuantityCell 提供正确的值。我的数据来自哪里的 plist 如下
这是我的代码
var restMenu = [[String:Any]]()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! RestaurantItemViewCell
cell.delegate = self as? TableViewCellDelegate
cell.selectionStyle = UITableViewCellSelectionStyle.none
//assign item name to cell
let selectedDictName = restMenu[indexPath.row] as NSDictionary
print("the selected dict ", selectedDictName)
cell.itemNameLabel.text = selectedDictName.value(forKey: "ItemName") as? String
// assign item price to cell
let selectedDictPrice = restMenu[indexPath.row] as NSDictionary
cell.itemPriceLabel.text = "Price: \(selectedDictPrice.value(forKey: "ItemPrice") as! String)"
// assign item quantity to cell
let selectedDictQuant = restMenu[indexPath.row] as NSDictionary
cell.itemQuantityLabel.text = selectedDictQuant.value(forKey: "ItemQuant") as? String
}