Skip to content
This repository has been archived by the owner on Apr 19, 2021. It is now read-only.

Programmatically setting a value for MultipleSelector #40

Closed
DylanNunns opened this issue Apr 21, 2015 · 1 comment
Closed

Programmatically setting a value for MultipleSelector #40

DylanNunns opened this issue Apr 21, 2015 · 1 comment

Comments

@DylanNunns
Copy link

Hey, I am trying to set a value using a MultipleSelector row, and can't figure out how to select one of the values by doing something such as row.value = "example"

In my code its for the purpose of editing an item after creating it.

In the example:

row = FormRowDescriptor(tag: Static.categories, rowType: .MultipleSelector, title: "Categories")
row.configuration[FormRowDescriptor.Configuration.Options] = [0, 1, 2, 3, 4]
row.configuration[FormRowDescriptor.Configuration.AllowsMultipleSelection] = true
row.configuration[FormRowDescriptor.Configuration.TitleFormatterClosure] = { value in
switch( value ) {
case 0:
return "Restaurant"
case 1:
return "Pub"
case 2:
return "Shop"
case 3:
return "Hotel"
case 4:
return "Camping"
default:
return nil
}
} as TitleFormatterClosure

if I was to do:
row.titleForOptionValue("Restaurant");
or row.titleForOptionValue(0);
or row.value = "Restaurant"
or row.title = "Restaurant"
Then the selected option still shows up as nothing

How can I get it so that it displays one of the options by default when the form loads?

Thanks

@DylanNunns
Copy link
Author

Figured it out. I need to set the row.value before configuring the TitleFormatterClosure.

Example:
row = FormRowDescriptor(tag: Static.categories, rowType: .MultipleSelector, title: "Categories")
row.configuration[FormRowDescriptor.Configuration.Options] = [0, 1, 2, 3, 4]
row.configuration[FormRowDescriptor.Configuration.AllowsMultipleSelection] = true
row.value = "Restaurant"
row.configuration[FormRowDescriptor.Configuration.TitleFormatterClosure] = { value in
switch( value ) {
case 0:
return "Restaurant"
case 1:
return "Pub"
case 2:
return "Shop"
case 3:
return "Hotel"
case 4:
return "Camping"
default:
return nil
}
} as TitleFormatterClosure

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant