我self.totalPriceLabel節目的所有店鋪Product.It的總價工作正常,但是,當我滾動cell
的熄滅屏幕由於dequeueReusableCellWithIdentifier
self.totalPriceLabel
獲得了不正確value.i現在的儲蓄存儲在NSUserDefaults
在數組值。如何在swift中用dequeueReusableCellWithIdentifier在UITableView中管理購物車?
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 =字符串( 「((self.totalPriceLabel.text!爲 的NSString).doubleValue + nextItemPrice)」)
如何獲得cell
值剛剛熄滅關閉屏幕?如何解決這個問題,由於滾動?
我覺得管理'totalPriceLabel'的方法不對,你應該把'totalPrice'放在一個變量中,當變量值更新時你需要更新標籤文本。 – amorbytes
@amorbytes。是的,我在viewcontroller的view.it的底部使用了單個變量totalPriceLabel,而不是在Tableview中 –