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.
Asked
Active
Viewed 795 times
-2
-
1Why aren't you using a `UIDatePicker`? – rmaddy Oct 06 '17 at 23:38
-
I tried it. It takes longer to navigate to the calendar date I desired to. – Luigi A. Cruz Oct 07 '17 at 00:13
-
I do not need the time component of the UI date picker. – Luigi A. Cruz Oct 07 '17 at 00:32
-
Set the date picker's mode to `.date` and you won't see the time on the picker. – rmaddy Oct 07 '17 at 01:35
1 Answers
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
-
-
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
-