Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a done button over the pickerview?

I want to display a picker view and a done button above the picker view .

I have a custom label which will become first responder . So when it becomes first responder I am displaying a picker view as the input view for my label. Now I want to have a done button on the picker to dismiss the picker view. I played with the inputAccesoryView property of UIPickerView but did not succeed . inputAccessoryView is possible with UITextView , not sure about the UIPickerView . Here is the link for how it can be done with UITextView

UITextView with “Done” button and “Return” key?

Has any body tried this , if someone knows how to do this for picker , please answer.

Thank you all in advance !!

like image 892
Bharat Jagtap Avatar asked Apr 08 '11 07:04

Bharat Jagtap


2 Answers

Add your picker view to an action sheet. First of all make sure youre view controller impliments UIPickerViewDelegate and UIActionSheetDelegate.

Then add this method, and call it when you want to show your picker.

- (void)showPicker {    
    UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Pick Value"
                                                      delegate:self
                                             cancelButtonTitle:@"Done"
                                        destructiveButtonTitle:nil
                                             otherButtonTitles:nil];

    UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,180,0,0)];
    pickerView.delegate = self;
    pickerView.dataSource = self;
    pickerView.showsSelectionIndicator = YES;    

    [menu addSubview:pickerView];
    [menu showInView:self.view.superview];

    //Change the height value in your CGRect to change the size of the actinsheet
    [menu setBounds:CGRectMake(0,0,320, 615)];

    [pickerView release]; 
    [menu release]; 
}
like image 178
Sabobin Avatar answered Sep 21 '22 14:09

Sabobin


I think you can try to put the picker inside a view with a 'Done' button and present that view

like image 22
visakh7 Avatar answered Sep 20 '22 14:09

visakh7