Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide a UIPickerView when the user make its choice

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"?

like image 662
TheInterestedOne Avatar asked Dec 13 '12 11:12

TheInterestedOne


3 Answers

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];
}
like image 107
Pétur Ingi Egilsson Avatar answered Sep 30 '22 13:09

Pétur Ingi Egilsson


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.

like image 31
Paras Joshi Avatar answered Sep 30 '22 12:09

Paras Joshi


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;
}
like image 42
Inder Kumar Rathore Avatar answered Sep 30 '22 12:09

Inder Kumar Rathore