Search code examples
iosswifteureka-forms

How to designing a custom PickerInlineRow with Eureka


I am currently trying to use Eureka, a easy to use form generator for iOS in Swift.

Everything is going smooth, except one thing:

How to design a custom PickerinlineRow like in the example app at example/InlineRows/PickerInlineRow

The code used there is the following:

<<< PickerInlineRow<NSDate>("PickerInlineRow") { (row : PickerInlineRow<NSDate>) -> Void in

    row.title = row.tag
    row.displayValueFor = {
        guard let date = $0 else{
        return nil
    }
    let year = NSCalendar.currentCalendar().component(.Year, fromDate: date)
        return "Year \(year)"
    }

    row.options = []
    var date = NSDate()
    for _ in 1...10 {
        row.options.append(date)
        date = date.dateByAddingTimeInterval(60*60*24*365)
    }
    row.value = row.options[0]
}

What I want to do is a same kind of InlinePicker but allowing the user to select 2 things: Month and Year. Problem is that I don't grasp the logic of the above piece of code, which var serve for what.

My current try are all totally not working.. If you have any idea.


Solution

  • You will need to create your custom picker for this.

    In the PickerInlineRow shown above the row.title is the title that appears on the left of the row while the displayValueFor block is used to define the value that appears on the right of the row.

    The row.options are the options shown in the picker, in your case you will have one option for each month you are adding.

    Finally the row.value is the value of the row which you can use to get what the user selected. You also have to update it accordingly.