4

I am using the Eureka forms swift library here: Eureka forms

I would like to have my first row of the input form become the first responder every time the view appears. I tried adding a .cellUpdate callback which is fired everytime the view appears, and doing a cell.becomeFirstResponder() but this did not work. Could someone with experience in this library please help? Thanks.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
demig0d
  • 1,131
  • 1
  • 12
  • 24

4 Answers4

7

Try this

import UIKit
import Eureka

class ViewController3: FormViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        form +++ Section("Custom cells")
            <<< TextRow("TextRow"){_ in
        }
    }

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        let row = self.form.rowByTag("TextRow") as! TextRow
        row.cell.textField.becomeFirstResponder()
    }
}

I hope this helps you

Reinier Melian
  • 20,519
  • 3
  • 38
  • 55
3

Hook it in cellSetup, this way we don't need to lookup the cell in viewDidAppear

form +++ Section("")
        <<< TextRow() {
            $0.title = "Name"
            $0.value = list?.name ?? ""
            $0.cellSetup() { cell, row in
                  cell.textField.becomeFirstResponder()
            }
            $0.onChange() {
                self.list.name = $0.value ?? ""
            }
        }
Phuah Yee Keat
  • 1,572
  • 1
  • 17
  • 17
1

Inspired by Reinier's answer, here is another way worked for me.

Directly call $0.cell.textField.becomeFirstResponder() in setting up the form.

        form +++ Section()
        <<< ZipCodeRow() {
            $0.value = postal_code
            $0.cell.textField.becomeFirstResponder()
            }
Q Liu
  • 737
  • 1
  • 5
  • 7
0

Swift 4:

In ViewDidLoad() add:

let row = self.form.rowBy(tag: "TextRow.tag") as! TextRow
row.cell.textField.becomeFirstResponder()
arakweker
  • 1,535
  • 4
  • 18
  • 40