I have an issue with my delegate for UIStepper
, TableViewCell
and TableViewController
. I am unable to pass a delegate command to my TableViewCell
in the TableViewController
.
My TableViewCell
code is as below:
CampTableCell.swift
import UIKit
protocol ReviewCellDelegate{
func stepperButton(stepper_value:Int)
}
class CampTableCell: UITableViewCell {
@IBOutlet var campqty: UILabel!
@IBOutlet var stepper: UIStepper!
var delegate:ReviewCellDelegate!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
@IBAction func stepperValueChanged(sender: UIStepper) {
self.delegate.stepperButton(Int(stepper.value))
campqty.text = String(Int(stepper.value))
}
}
The start of my TableGenController.swift is this:
class TableGenController: UITableViewController, UISearchBarDelegate, ReviewCellDelegate {
and I have added this function (as a test):
func stepperButton(stepper_value:Int) {
print("Value Changed!")
}
Next, I believe, is I have to add this under viewDidLoad:
CampTableCell.delegate = self
However, this causes an error stating that:
Instance member 'delegate' cannot be used on type 'CampTableCell'
I might be doing something conceptually wrong, but it's been difficult to find resources for this particular setup. Would be really grateful for some help on this, thanks!