如何使用 Eureka 设计自定义 PickerInlineRow
How to designing a custom PickerInlineRow with Eureka
我目前正在尝试使用 Eureka,一个易于使用的表单生成器,用于 Swift 中的 iOS。
一切都很顺利,除了一件事:
如何像 example/InlineRows/PickerInlineRow
中的示例应用一样设计自定义 PickerinlineRow
那里使用的代码如下:
<<< PickerInlineRow<NSDate>("PickerInlineRow") { (row : PickerInlineRow<NSDate>) -> Void in
row.title = row.tag
row.displayValueFor = {
guard let date = [=10=] 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]
}
我想做的是同一种 InlinePicker,但允许用户 select 两件事:月和年。问题是我没有把握上面这段代码的逻辑,which var serve for what.
我目前的尝试都是完全行不通的..如果你有什么想法。
您需要为此创建 custom picker。
在上面显示的 PickerInlineRow 中,row.title 是出现在行左侧的标题,而 displayValueFor
块用于定义出现在行右侧的值。
row.options
是选择器中显示的选项,在您的情况下,您添加的每个月都会有一个选项。
最后 row.value
是行的值,您可以使用它来获取用户选择的内容。您还必须相应地更新它。
我目前正在尝试使用 Eureka,一个易于使用的表单生成器,用于 Swift 中的 iOS。
一切都很顺利,除了一件事:
如何像 example/InlineRows/PickerInlineRow
中的示例应用一样设计自定义 PickerinlineRow那里使用的代码如下:
<<< PickerInlineRow<NSDate>("PickerInlineRow") { (row : PickerInlineRow<NSDate>) -> Void in
row.title = row.tag
row.displayValueFor = {
guard let date = [=10=] 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]
}
我想做的是同一种 InlinePicker,但允许用户 select 两件事:月和年。问题是我没有把握上面这段代码的逻辑,which var serve for what.
我目前的尝试都是完全行不通的..如果你有什么想法。
您需要为此创建 custom picker。
在上面显示的 PickerInlineRow 中,row.title 是出现在行左侧的标题,而 displayValueFor
块用于定义出现在行右侧的值。
row.options
是选择器中显示的选项,在您的情况下,您添加的每个月都会有一个选项。
最后 row.value
是行的值,您可以使用它来获取用户选择的内容。您还必须相应地更新它。