How to hide a UIPickerView when the user make its choice
Solution 1
I'm using a UIPickerView as the inputView for a TextField (thus replacing the onscreen keyboard). I use the following delegate to dismiss the view.
#pragma mark - UIPickerViewDelegate
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
// Code logic
[[self view] endEditing:YES];
}
Solution 2
use the delegate method of UIPickerView
like bellow..
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
yourTextField.text = [yourArray objectAtIndex:row];
thePickerView.hidden = YES;
}
Also you can take one UIButton
and hide this with action event of UIButton
.
Solution 3
Add this line where you have created picker
picker.delegate = self;
your callback
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
picker.hidden=YES;
}
TheInterestedOne
I'm an energy and nuclear engineer, fintech startupper and entrepreneur, and now studiyng Artificial Intelligence (Master after Master)
Updated on June 05, 2022Comments
-
TheInterestedOne almost 2 years
I've created a custom UIPickerView with the following code
UIPickerView *picker =[[UIPickerView alloc] initWithFrame:CGRectMake(139,50,161,30)]; picker.delegate=self; picker.showsSelectionIndicator=YES; picker.hidden=NO; [self.view addSubview:picker];
Now I want to hide the pickerView when the user make its choice of a row simply with
picker.hidden=YES;
Now: 1) How can I recognize the choice of the user and then hide the unuseful pickerview? 2) Can I show the choice in a TextField? with @"choice"?