swift - How to set text value when I used pickerview with multiple components -
i implemented demo of picker view multiple component
when set value text right want output
one 1 but set
1 1 2 2 below code:
var pickdata = [ ["one","two"], ["1","2"] ] func pickerview(_ pickerview: uipickerview, numberofrowsincomponent component: int) -> int { return pickdata.count } func numberofcomponents(in pickerview: uipickerview) -> int { return 2 } func pickerview(_ pickerview: uipickerview, titleforrow row: int, forcomponent component: int) -> string? { return pickdata[component][row] } func pickerview(_ pickerview: uipickerview, didselectrow row: int, incomponent component: int) { activetextfield.text = pickdata[component][row] print(pickdata[component][row]) }
like @david mentioned changing data structure dictionary right approach. if looking easy hack code help, though not best approach. output "one 1" , on can useful
var pickdataindices = ["1", "2"] var pickdata = ["one", "two"] func pickerview(_ pickerview: uipickerview, numberofrowsincomponent component: int) -> int { return pickdata.count } func numberofcomponents(in pickerview: uipickerview) -> int { return 1 } func pickerview(_ pickerview: uipickerview, titleforrow row: int, forcomponent component: int) -> string? { return pickdata[row] } func pickerview(_ pickerview: uipickerview, didselectrow row: int, incomponent component: int) { activetextfield.text = pickdata[row] print("%@ %@",pickdata[row], pickdataindices[row]) }
Comments
Post a Comment