Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
- {
- let cell = ingredientTableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! IngredientTableViewCell
- cell.ingredientNameTextField.text = ingredients [indexPath.row].ingredientName
- cell.numberofItem.text = "1"
- let cellcalory = ingredients [indexPath.row].ingredientCalory
- cell.itemTotalCalory.text = cellcalory
- cell.plusButton.tag = Int(cell.itemTotalCalory.text!)! //indexPath.row
- cell.plusButton.addTarget(self, action:#selector(plusAction), for: .touchUpInside)
- cell.minusButton.tag = Int(cell.itemTotalCalory.text!)!
- cell.minusButton.addTarget(self, action:#selector(minusAction), for: .touchUpInside)
- return cell
- }
- @IBAction func plusAction(sender: UIButton)
- {
- let cell = ingredientTableView.dequeueReusableCell(withIdentifier: "cell") as! IngredientTableViewCell
- let buttonRow = sender.tag
- if cell.numberofItem.text == "1" || cell.numberofItem.text != "1"
- {
- cell.numberofItem.text = "1"
- let textValue1 = cell.numberofItem.text
- var textValue = Int(textValue1!)
- textValue = textValue! + 1
- cell.numberofItem.text = String(describing: textValue)
- let oldcalory = buttonRow
- cell.itemTotalCalory.text = String (((textValue! * Int(oldcalory)) + Int(oldcalory)))
- let newcalory = cell.itemTotalCalory.text
- refresh(newcalory: newcalory!);
- }
- }
- func refresh(newcalory :String)
- {
- let cell = ingredientTableView.dequeueReusableCell(withIdentifier: "cell") as! IngredientTableViewCell
- cell.itemTotalCalory.text = newcalory
- DispatchQueue.main.async {
- self.ingredientTableView.reloadData()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement