1

So I'm trying to separate out my delegate into a separate class instead of housing it in my cell class. Here's how I declare and initialize the delegate:

class RegistrationTableViewController: BaseTableViewController, UITextFieldDelegate {
var textFieldDelegate: UITextFieldDelegate

//MARK: - Initialization

required init?(coder aDecoder: NSCoder) {
    textFieldDelegate = RegistrationTextFieldDelegate()

    super.init(coder: aDecoder)
}

Then I set it in my general cell setup method:

func setupBaseCellWithType(type: Constants.Registration.CellType) -> BaseCell {
    var cell: BaseCell? = nil

    if let newCell = tableView.dequeueReusableCellWithIdentifier(Constants.Registration.profileBaseRegistrationCell) as? BaseProfileCell {
        newCell.cellType = type
        newCell.setupCell()
        newCell.setTextFieldDelegate(textFieldDelegate)
        cell = newCell
    }

    return cell!
}

The problem is, it never hits any of the delegate methods. It was working great when I made the cells my delegate, any idea whats going wrong here?

Edit: setTextFieldDelegate calls this method:

private func setTextFieldDelegates(delegate: UITextFieldDelegate) -> Void {
    for textField in textFieldArray {
        textField.delegate = delegate
    }
}

That was how I set the delegate on all my textFields in the cell previously, so I know it's correctly setting them there, but something is going wrong in me trying to move it to another class.

Edit 2: I'm an idiot who's running on low sleep. I was only changing the BaseCell delegate, not my PhoneNumberCellDelegate... Feel free to call me an idiot if you'd like.

Shripada
  • 6,296
  • 1
  • 30
  • 30
Bill L
  • 2,576
  • 4
  • 28
  • 55
  • I don't know if it makes a difference, but there is an `s` after `setTextFieldDelegate` in the declaration of `setTextFieldDelegate`. – tktsubota Dec 22 '15 at 01:17
  • What I meant by that was the method `setTextFieldDelegate` calls an internal private method called `setTextFieldDelegates`. However.... I am not the smartest tonight... I guess loss of sleep will do that... I never actually changed the delegate on the cell I was testing out with.... Editing now. – Bill L Dec 22 '15 at 01:18
  • Could you post the implementation of your `RegistrationTextFieldDelegate` class? – Bell App Lab Dec 22 '15 at 09:51

0 Answers0