Eureka inline picker row select first row

Viewed 892

When I expand the PickerInlineRow, I want to be able to select the first option. For cases where there is only one option, I cannot call the onChange method so it can never be picked.enter image description here

2 Answers

This is a hack.. But I select the first row by setting the row value = the first element in the array on the network callback.

  if let row = self.form.rowBy(tag: "Row") as? PickerInlineRow<RowType> {
    row.value = rowTypes.first
    row.reload()
  }

let assume you've created array or objects let items = ["1","2","3","4","5","6"]

<< PickerInlineRow<String>(){
            row in
            row.tag = "inlineRow"
            row.options = items
            row.title = "Tap to select"
            row.displayValueFor = {
                guard let teacherName = $0 else {return nil}
                return teacherName.name
            }
            }.onChange({ (row) in
                guard let value = row.value else {return}
                print(value)
                self.selectedTeacher = value
                print("Selected teacher name :\(self.selectedTeacher.name) , ID : \(self.selectedTeacher.id)")
            }).onCellSelection({ (cell, row) in
                row.value = items.first
                row.reload()
            })

Here .onCellSelection is called when user taps on the row so we will get the first value from our array and put the value in row and reload the row .

Related