Моего self.totalPriceLabel шоу общей цена всего магазина Product.It работает нормально, но когда это я прокручивать cell
идти от экрана из-за dequeueReusableCellWithIdentifier
self.totalPriceLabel
получают неправильные value.i копят значение в массиве, который хранится в NSUserDefaults
.Как управлять корзиной покупок в UITableView с помощью dequeueReusableCellWithIdentifier в swift?
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell : CartCell? = tableView.dequeueReusableCellWithIdentifier("cartCell") as! CartCell!
if(cell == nil)
{
cell = CartCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cartCell")
}
cell?.itemCount.layer.cornerRadius = 5
cell?.clipsToBounds = true
cell?.itemCount.layer.borderWidth = 1
cell?.itemCount.layer.borderColor = UIColor.blackColor().CGColor
cell?.itemMinus.tag = indexPath.row
cell?.itemPlus.tag = indexPath.row
cell?.itemDelete.tag = indexPath.row
let key = self.readArray[indexPath.row]
cell?.itemCount.text = String("\(key.allValues[0])")
let tupleVar = getProductNameFromCharacter(String("\(key.allKeys[0])"))
cell?.itemName.text = tupleVar.tempName
cell?.itemPrice.text = String("\(tupleVar.price)")
//Actual Logic
let tempCount = key.allValues[0] as! Double
let nextItemPrice = (cell!.itemPrice.text! as NSString).doubleValue * tempCount
self.totalPriceLabel.text = String("\((self.totalPriceLabel.text! as NSString).doubleValue + nextItemPrice)")
return cell!
}
Проблема: Как прокрутки cell
получения неправильно values.for self.totalPriceLabel
.
self.totalPriceLabel.text = String ("((self.totalPriceLabel.text! В NSString) .doubleValue + nextItemPrice)")
Как получить cell
значение, которое только выходит от экран? как исправить эту проблему из-за прокрутки?
Я считаю неправильный подход к управлению 'totalPriceLabel', вы должны взять ваш' totalPrice' в одну переменную, и вам нужно обновить текст метки, когда значение переменной будет обновлено. – amorbytes
@amorbytes. Да, я взял одну переменную totalPriceLabel в нижней части viewcontroller view.it не в Tableview –