Uipicker view of array

Asked

Viewed 37 times

0

Good night people... I have the following problem : I need to insert a Picker view into my application, this Picker view receives the data from an array, and when the user clicks on a button an action triggers that takes the pickView value (it can be up to the position in the array) and changes the text of a label. I’ve tried several tutorials on the internet, however all or give compilation problem , or when testing on the iphone of the problem when opening the view. Could someone please or refer me to a well explained tutorial that is working or could you show me how it does ? Thank you

  • Your doubt has been since the creation of this UIPickerView and fill it, or just get the selected value to fill the UILabel?

  • Friend managed to populate the Picker view... How do I know which option my user has selected, or whichever function I can run to know which one is selected ? type a . text

1 answer

1


Since you already have the UIPickerView set and with the appropriate values, to get who is selected, if you only have a component, do so:

let selecionado: Int = pickerView.selectedRowInComponent(0)

And with the variable selecionado, you identify the value of array to fill your UILabel.

  • This function returns the selected line right ? what would this 0 ?

  • It’s because your UIPickerView may contain several components, when that "wheel" is divided into several, for example the UIDatePickerView It’s like a normal Picker view, only with one component for the day, another for the time and so on. So if you only have one component, zero means I’m taking this one first. The number of components you define in delegate numberOfComponentsInPickerView.

  • I understood thank you very much...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.