0

I have UITableView with UITextFields in custom cells.

For UITextField I use custom inputView:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier, forIndexPath: indexPath) as! Item

        cell.price.text = ""
        cell.price.delegate = self

        return cell
    }

func textFieldDidBeginEditing(textField: UITextField) {
        textField.inputView = keyboardView
        itemPrice = textField
    }

func numberWasTapped(number: String!) {
        itemPrice.insertText(number!)
    }

With delegate method:

@IBAction func keyTaped(sender: UIButton) {
      switch sender.tag {
        case 112:
          if !isCommaWasPressed {
             isCommaWasPressed = true
             sender.enabled = false
             self.delegate?.numberWasTapped(sender.titleLabel!.text)
           }
           break
       default:
           self.delegate?.numberWasTapped(sender.titleLabel!.text)
       }

My custom inputView is the calculator keyboard with the all logic in the Keyboard class: it controls if comma was pressed and how many numbers was entered after the comma. For example, if comma was pressed, then commaButton.enabled = false in Keyboard class.

I couldn't figure out how to set the commaButton.enabled = true in Keyboard class when I'm switching to another UITextField.

I tried textField.reloadInputViews() in textFieldDidBeginEditing(_:) method but it doesn't work.

I think, I should get the information from UITextField and pass it to Keyboard's class logic. But I don't know how to do it.

Oleksandr Fisun
  • 193
  • 2
  • 5
  • 10
  • What your saying is, after clicking a different cell from the previous one you need to change some property on the previous cell, which in this case is the commaButton.enable, right? – Diogo Antunes May 08 '16 at 14:08
  • Hi @diogo-antunes. – Oleksandr Fisun May 09 '16 at 04:06
  • Hi @diogo-antunes. `commaButton` is the `UIButton` in custom `inputView` for `textField` in a cell. `commaButton` is declared in Keyboard class. Keyboard class has delegate method: `@IBAction func keyTaped(sender: UIButton) { switch sender.tag { case 112: if !isCommaWasPressed { isCommaWasPressed = true sender.enabled = false self.delegate?.numberWasTapped(sender.titleLabel!.text) } break default: self.delegate?.numberWasTapped(sender.titleLabel!.text) } ` – Oleksandr Fisun May 09 '16 at 04:20
  • Updated description of issue. – Oleksandr Fisun May 09 '16 at 05:40

1 Answers1

0

I found the solution. I moved keyboard logic to main ViewController and no need to pass textField data to Keyboard class.

Oleksandr Fisun
  • 193
  • 2
  • 5
  • 10