-2

I am using xCode 9 and Swift 3(?). How do you select an item in UI picker view at runtime and/or via button? Once clicked via button, UI picker view must also be updated. Thank you.

Screenshot for the above inquiry.

1 Answers1

0

Call – selectRow:inComponent:animated: when you click on any of the buttons. See PickerView for more details.

EDIT:

(after you connect your PickerView to your code - it can be called anything)

i.e.:

April:

myPickerView.selectRow(aprilRow, inComponent: 0, animated: false)

16th Day:

myPickerView.selectRow(16, inComponent: 1, animated: false)

Today's Date:

myPickerView.selectRow(todaysMonth, inComponent: 0, animated: false)
myPickerView.selectRow(todaysDay, inComponent: 1, animated: false)
etc...
CodeNinja
  • 616
  • 4
  • 18
  • I want to have specific items in the picker view set at runtime or via button. Once the button is clicked, the picker view must also reflect those. Please refer to the provided screenshot. Thank you. – Luigi A. Cruz Oct 06 '17 at 23:28
  • @LuigiA.Cruz I posted a small example of what I was mentioning – CodeNinja Oct 06 '17 at 23:33
  • Did this. pickerView.selectRow(3, inComponent: 0, animated: false) But it shows this error message: Ambiguous reference to member 'pickerView(_:numberOfRowsInComponent:)' . What will I do with this? – Luigi A. Cruz Oct 06 '17 at 23:50
  • Solved. UI picker view in view controller must be dragged to source code before I can use those you suggested and must be named pickerView. Thank you. – Luigi A. Cruz Oct 07 '17 at 00:08
  • Yes, sorry should have clarified that. Glad it worked! – CodeNinja Oct 07 '17 at 00:10