Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Dismiss a UIPIckerView once the user has selected their choice

I have my UIPickerView hooked into a UITextField's inputView. I have it popping up. I know when the user selects a row. I know the value for the row. All that is great.

My question deals with when to dismiss the picker. I've seen people marry a toolbar with [Cancel] and [Done] to the picker and dismiss it on either button click. This is probably the best approach as the user can back out of their choice.

I've also seen one app where the user scrolls to the selection they want and then presses it again to dismisses the picker. I would like to know how to do this. I have noticed that once the picker informs you of a specific row being selected, it will not inform you again if the user continues to click/press on the same active row.

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
like image 697
Userdano Avatar asked Oct 11 '11 03:10

Userdano


1 Answers

Hey UserDano since you have added the picker as an ipnputView to the text field you can call

 [outletForTextField resignFirstResponder] 

and this will help you resign the pickerView . Now The way you want to do this is on first selection you want to Select the value and on second selecteion (for same row) you want to hide the Picker.So keeping a Bool value to store the selected value and later using it to remove the picker when same row is selected might do the trick. Hope it helps

like image 59
Rahul Sharma Avatar answered Oct 04 '22 17:10

Rahul Sharma