I have a tableview contains some tableviewcell with UIStepper. This is tableviewcell code:
class ShoppingCartItemCell: UITableViewCell {
static let reuseIdentifier = "ShoppingCartItemCell"
@IBOutlet weak var itemImage: UIImageView!
@IBOutlet weak var itemNameLabel: UILabel!
@IBOutlet weak var itemProviderLabel: UILabel!
@IBOutlet weak var itemPriceLabel: UILabel!
@IBOutlet weak var itemQuantityText: UITextField!
@IBOutlet weak var quantityStepper: UIStepper!
var oldValue = 0.0
var itemName = "" {
didSet {
itemNameLabel.text = itemName
}
}
var itemProvider = "" {
didSet {
itemProviderLabel.text = itemProvider
}
}
var itemPrice = "" {
didSet {
itemPriceLabel.text = itemPrice
}
}
var itemQuantity = "" {
didSet {
itemQuantityText.text = itemQuantity
}
}
}
And this is uistepper code in tableview:
class ShoppingCartViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
@IBAction func quantityStepper(_ sender: UIStepper) {
ShoppingCartItemCell.itemQuantity = "\(Int(sender.value))"// this way is not possible...
// How to update the quantityStepper value in ShoppingCartItemCell class here
}
}
How to update the quantityStepper value in ShoppingCartViewController class? Some people will tell me to create @IBAction of quantityStepper in ShoppingCartItemCell class but my business logic must to do this way. Please help. Thanks all.