Bharat Jagtap
Bharat Jagtap

Reputation: 1692

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 !!

Upvotes: 6

Views: 15203

Answers (2)

Sabobin
Sabobin

Reputation: 4276

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]; 
}

Upvotes: 3

visakh7
visakh7

Reputation: 26390

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

Upvotes: 1

Related Questions