Domanda

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]
È stato utile?

Soluzione

-(void)inputAccessoryViewDidFinish

{
   [self.someInput resignFirstResponder];
}

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

Altri suggerimenti

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

This tutorial can get you started.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top