ios - Swift - how to concatenate didSelectRow selections from UIPickerView -
i have 2 column picker (miles , tenths)
picker seems work well, cannot seem work out how concatenate selections 2 columns i.e. if user selects 23 first column , 6 second column, want create answer of "23.6"
at moment, either column selection overwrites previous selection.
btw: don't think can append 2 strings because happens if user selects 10ths first?
let resetpickerdata = [array(0...99), array(0...9)] // returns number of 'columns' display. func numberofcomponentsinpickerview(pickerview: uipickerview!) -> int{ return 2 } // returns # of rows in each component.. func pickerview(pickerview: uipickerview!, numberofrowsincomponent component: int) -> int{ return resetpickerdata[component].count } func pickerview(pickerview: uipickerview!, titleforrow row: int, forcomponent component: int) -> string! { return string(resetpickerdata[component][row]) } func pickerview(pickerview: uipickerview!, didselectrow row: int, incomponent component: int) { //var distance = ?? }
you'll need keep track of component selection separately concant strings:
var firstcomponentstring = "" var secondcompoentstring = "" func pickerview(pickerview: uipickerview!, didselectrow row: int, incomponent component: int) { if component == 0 { firstcomponentstring = string(resetpickerdata[component][row]) } else if component == 1 { secondcompoentstring = string(resetpickerdata[component][row]) } var displaystring = "\(firstcomponentstring).\(secondcompoentstring)" }
Comments
Post a Comment