How to undo a UIPIckerView as soon as a user selects his choice

I have a UIPickerView connected to UITextField's input view. It appears to me. I know when the user selects a row. I know the value for the string. All this is great.

My question is when to reject the collector. I saw people marry a toolbar using [Cancel] and [Finish] to the collector and discard it when any button is pressed. This is probably the best approach, as the user may opt out.

I also saw one application in which the user scrolls the desired selection and then clicks it again to cancel the selector. I would like to know how to do this. I noticed that after the collector informs you of the selected line, it will not inform you again if the user continues to click / click on the same active line.

 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 
+7
source share
2 answers

Hi UserDano, since you added the collector as ipnputView to the text box that you can call

  [outletForTextField resignFirstResponder] 

and this will help you resign pickerView. Now the way you want to do this is to select the first choice that you want to select and the second choice (for the same row) that you want to hide the Picker. By saving the Bool value to save the selected value, and then using it to delete the collector, when the same row is selected, it can do the trick. Hope this helps.

+2
source

If you want to learn how to reject a selection view by clicking on a button, you can put this snippet that I used in one of my projects:

  NSInteger selectedRow=[yourPickerView selectedRowInComponent:0];// i assume your picker have one component NSString *item=[yourPickerView objectAtIndex:selectedRow];//get the selected item yourTextField.text=[NSString stringWithFormat:@"%@",item];//display the selected item in the text field [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.5]; CGAffineTransform transform=CGAffineTransformMakeTranslation(0, 480); yourPickerView.transform=transform; [UIView commitAnimations];//dismiss the view controller which contains the picker view 

Put the code above in your IBAction method. Hope this helps.

0
source

All Articles