I need to call a function when the user finishes filling the form and presses Ok (on the keyboard toolbar) on the last field. I need help figuring out how to do this.
The last row is a DateRow, I tried setting the target and action of the toolbar and it works sometimes, others it doesn't -- first time yes, but if I go back to another row and back to the last, no.
let birthdayRow = DateRow()
override func viewDidLoad() {
super.viewDidLoad()
form +++ Section() <<< birthdayRow
let toolbar = (birthdayRow.cell.datePicker.inputAccessoryView as! UIToolbar)
let okButton = toolbar.items!.last!
okButton.target = self
okButton.action = #selector(save)
}
func doSomething() {
//...
}
Would love to know that too
I've just figured out this myself. You will need to use the onCellHighlightChanged callback with row.isHighlighted property.
Example:
<<< TextRow() {
$0.title = "Something"
}.onCellHighlightChanged { cell, row in
if !row.isHighlighted {
// Do things here
}
}
Hope I've helped!
Seem like the row.isHighLighted is always return true when the textfield is not focus anymore. Are there any way to get the action when user tapped on return button?
This is now possible by overriding func inputAccessoryView(for row: BaseRow) -> UIView? like this:
override func inputAccessoryView(for row: BaseRow) -> UIView? {
let iaView = super.inputAccessoryView(for: row)
guard let iaNavigationView = iaView as? NavigationAccessoryView else {
return iaView
}
iaNavigationView.doneButton.action = #selector(NavigationAccessoryController.tapped)
return iaNavigationView
}
Most helpful comment
I've just figured out this myself. You will need to use the
onCellHighlightChangedcallback withrow.isHighlightedproperty.Example:
Hope I've helped!