UIPickerView as inputView not hiding on iPad

1.1k views Asked by At

I have added UIPickerView as inputView to UITextField in my app. It works perfectly on iPhone, but when I run the same code on iPad, my pickerView does not hide on clicking done button.
Some code:

picker = [[UIPickerView alloc] initWithFrame:CGRectZero];
picker.delegate = self;
picker.dataSource = self;
[picker setShowsSelectionIndicator:YES];
self.someInput.inputView = provincePicker;

UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]
    initWithBarButtonSystemItem:UIBarButtonSystemItemDone
    target:self action:@selector(inputAccessoryViewDidFinish)];
[pickerToolbar setItems:[NSArray arrayWithObject:doneButton] animated:NO];
self.someInput.inputAccessoryView = pickerToolbar;

What do I have to change (add?) to make picker disappear?

edit: inputAccessoryViewDidFinish is my method, it just calls

[self.someInput resignFirstResponder]
2

There are 2 answers

1
Abdullah Shafique On BEST ANSWER
-(void)inputAccessoryViewDidFinish

{
   [self.someInput resignFirstResponder];
}

EDIT: Implement -disablesAutomaticKeyboardDismissal and return NO. That should alllow the keyboard to dismiss.

1
geekchic On

You need to use the UIPopOverController to achieve the same results.

This tutorial can get you started.