0

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!

Eric Aya
  • 69,473
  • 35
  • 181
  • 253

1 Answers1

0

I'm not proficient in delegates, but have you tried removing the line with the error? I'm not sure you need it.

Also I think you can remove self in

self.delegate.stepperButton(Int(stepper.value))
Shades
  • 5,568
  • 7
  • 30
  • 48