title: Element in TableViewCell has multiple reference
body: <p>I have a TableView in which I load custom cells.
  In a custom cell there is a textfield which while tableview populates itself loads a custom dial pad close itself.
  This floating numeric keyboard during its initialization it's passed the textfield element. But anytime I pressed a button in the numeric keyboard the text field does not change (this happens only in table view cells).</p>
  
  <p>So recap:</p>
  
  <p>UICellView -> with inside -> UITextField
  CustomDialPad (UIView) is initialized while UICellView is loaded by its UITableView
  During CustomDialPad inizialization to a method of its class is passed the UITextField</p>
  
  <p>When I press one of the buttons in the CustomDialPad the UITextField does not modify itself.</p>
  
  <p>So I printed in 3 different phase the dump of the UITextField element.</p>
  
  <p><strong>Phase 1 Result - Dump of the UITextField while the cell is loading:</strong></p>
  
  <pre><code>▿ Optional(&lt;UITextField: 0x7fa83c0cd200; frame = (358 6; 104 30); text = '103.12'; opaque = NO; autoresize = RM+BM; layer = &lt;CALayer: 0x60c000229ae0&gt;&gt;)
    - some: &lt;UITextField: 0x7fa83c0cd200; frame = (358 6; 104 30); text = '103.12'; opaque = NO; autoresize = RM+BM; layer = &lt;CALayer: 0x60c000229ae0&gt;&gt; #0
      - super: UIControl
        - super: UIView
          - super: UIResponder
            - super: NSObject
  </code></pre>
  
  <p><strong>Phase 2 Result - Dump of the UITextField while it load the CustomDialPad:</strong></p>
  
  <pre><code>- &lt;UITextField: 0x7fa83c0cd200; frame = (358 6; 104 30); text = '103.12'; opaque = NO; autoresize = RM+BM; gestureRecognizers = &lt;NSArray: 0x60c00005d190&gt;; layer = &lt;CALayer: 0x60c000229ae0&gt;&gt; #0
    - super: UIControl
      - super: UIView
        - super: UIResponder
          - super: NSObject
  ▿ Optional(&lt;UITextField: 0x7fa83c096a00; frame = (358 6; 104 30); text = '103.12'; opaque = NO; autoresize = RM+BM; layer = &lt;CALayer: 0x60c00022b8a0&gt;&gt;)
    - some: &lt;UITextField: 0x7fa83c096a00; frame = (358 6; 104 30); text = '103.12'; opaque = NO; autoresize = RM+BM; layer = &lt;CALayer: 0x60c00022b8a0&gt;&gt; #0
      - super: UIControl
        - super: UIView
          - super: UIResponder
            - super: NSObject
  </code></pre>
  
  <p><strong>Phase 3 Result - Dump of the UITextField while a button of the CUstomDialPad is pushed</strong></p>
  
  <pre><code>▿ Optional(&lt;UITextField: 0x7fa83c0cd200; frame = (358 6; 104 30); text = '103.12'; opaque = NO; autoresize = RM+BM; gestureRecognizers = &lt;NSArray: 0x60c00005d190&gt;; layer = &lt;CALayer: 0x60c000229ae0&gt;&gt;)
    - some: &lt;UITextField: 0x7fa83c0cd200; frame = (358 6; 104 30); text = '103.12'; opaque = NO; autoresize = RM+BM; gestureRecognizers = &lt;NSArray: 0x60c00005d190&gt;; layer = &lt;CALayer: 0x60c000229ae0&gt;&gt; #0
      - super: UIControl
        - super: UIView
          - super: UIResponder
            - super: NSObject
  </code></pre>
  
  <p>As you can see here are the reference in the 3 different phases:</p>
  
  <pre><code>Phase 1: Optional(UITextField: 0x7fa83c0cd200)
  Phase 2: UITextField: 0x7fa83c0cd200
           Optional(UITextField: 0x7fa83c096a00)
  Phase 3: Optional(UITextField: 0x7fa83c0cd200)
  </code></pre>
  
  <p>Why do I have 2 different references in phase 2?
  Could it be that the reason why values in UITextFields don't change during CustomDialPad's buttons pushing?
  How can I retrieve the element with the reference same in the other phases in Phase 2?</p>
  
  <p>Regards,
  Matteo </p>
  
  <p>Helping Code:</p>
  
  <p>Custom UIView class NumbersPadView</p>
  
  <pre><code>class NumbersPadView: UIView {
      @IBOutlet weak var number1: UIButton!
      @IBOutlet weak var number2: UIButton!
      @IBOutlet weak var number3: UIButton!
      @IBOutlet weak var number4: UIButton!
      @IBOutlet weak var number5: UIButton!
      @IBOutlet weak var number6: UIButton!
      @IBOutlet weak var number7: UIButton!
      @IBOutlet weak var number8: UIButton!
      @IBOutlet weak var number9: UIButton!
      @IBOutlet weak var zero: UIButton!
      @IBOutlet weak var dot: UIButton!
      @IBOutlet weak var delete: UIButton!
      @IBOutlet weak var done: UIButton!
  
      var connectedTextField: UITextField!
      var isFirstInput = true
  
      override func draw(_ rect: CGRect) {
          // Drawing code
      }
  
      func showMyself(showing: UIView, element: UITextField) {
          self.connectedTextField = element
          self.connectedTextField.resignFirstResponder()
          self.isFirstInput = true
          self.connectedTextField.selectedTextRange = self.connectedTextField.textRange(from: self.connectedTextField.beginningOfDocument, to: self.connectedTextField.endOfDocument)
          self.alpha = 0.0
          let frame = showing.convert(self.connectedTextField.frame, from:self.connectedTextField.superview)
          self.frame.origin.x = CGFloat(Double(frame.origin.x) - Double(self.frame.width) - 2)
          self.frame.origin.y = CGFloat((Double(frame.origin.y) + Double(element.frame.height) / 2) - Double(self.frame.height) / 2)
  
          if self.superview == nil {
              showing.addSubview(self)
          }
  
          UIView.animate(withDuration: 0.4, animations: {
              self.alpha = 1.0
          })
          dump(self.connectedTextField) //Phase 2
      }
  
      @IBAction func buttonPressed(_ sender: UIButton) {
          if (isFirstInput) {
              self.connectedTextField.text = ""
          }
          self.isFirstInput = false
          switch sender.tag {
          case 10: //zero
              self.connectedTextField.text = self.connectedTextField.text! + "0"
              break
          case 12: //back
              if self.connectedTextField.text != "" {
                  var tmpText = self.connectedTextField.text
                  tmpText = tmpText?.substr(start: 1, length: (tmpText?.length)! - 1)
                  self.connectedTextField.text = tmpText
                  if tmpText == "." {
                      tmpText = tmpText?.substr(start: 1, length: (tmpText?.length)! - 1)
                      self.connectedTextField.text = tmpText
                  }
              }
              break
          case 13:
              if self.connectedTextField.text != "" &amp;&amp; self.connectedTextField.text?.range(of:".") == nil {
                  self.connectedTextField.text = self.connectedTextField.text! + "."
              }
              break
          default:
              self.connectedTextField.text = self.connectedTextField.text! + String(sender.tag)
              break
          }
          self.connectedTextField.selectedTextRange = self.connectedTextField.textRange(from: self.connectedTextField.endOfDocument, to: self.connectedTextField.endOfDocument)
          dump(self.connectedTextField) //Phase 3
      }
  
      @IBAction func donePressed(_ sender: UIButton) {
          let tmpDoubleValue = self.connectedTextField.text?.getDouble()
          self.connectedTextField.text = tmpDoubleValue?.toString(2)
          self.connectedTextField.selectedTextRange = self.connectedTextField.textRange(from: self.connectedTextField.endOfDocument, to: self.connectedTextField.endOfDocument)
          UIView.animate(withDuration: 0.3, animations: {
              self.alpha = 0.0
          })
          self.connectedTextField.resignFirstResponder()
      }
  </code></pre>
  
  <p>Populating UITableViewCell</p>
  
  <pre><code>func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
              let tmpCell = Bundle.main.loadNibNamed("ItemCellNew", owner: self, options: nil)?.first as! ItemCellNew
              tmpCell.setCell(item: items[indexPath.row])
              tmpCell.POSItemsFunctionsDelegate = self
              if self.idOrder != "" {
                  tmpCell.setOrderCell()
              }
              dump(tmpCell.amountInput) // Phase 1
              return tmpCell
          }
  </code></pre>
  
  <p>Cell Method setCell()</p>
  
  <pre><code>func setCell(item: itemStruct) {
          if item.realQty &lt; item.qty {
              self.bkgView?.backgroundColor = UIColor(named: "NO_QUANTITY")
          }
          self.title.text = item.title
          self.brand.text = item.brand
          self.qty.text = String(item.qty)
          self.amountInput.text = String(item.prc)
          self.subTotal.text = String(item.prc * Double(item.qty))
          self.amountInput.setShowingNumberPad()
      }
  </code></pre>
  
  <p>Entension for UITextField:</p>
  
  <pre><code>func setShowingNumberPad() {
          self.addTarget(self, action: #selector(didEditingBegin(_:)), for: .editingDidBegin)
      }
  
      @objc func didEditingBegin(_ sender:UITextField) {
          var customKeyboard: NumbersPadView!
          let views = sender.parentViewController?.view.subviews.filter{$0 is NumbersPadView}
          if views?.count == 0 {
              customKeyboard = (Bundle.main.loadNibNamed("NumbersPadView", owner: self, options: nil)?.first as? NumbersPadView)!
          } else {
              customKeyboard = views?.first as! NumbersPadView
          }
          customKeyboard.showMyself(showing: (self.parentViewController?.view)!, element: sender as UITextField)
      }
  </code></pre>