質問

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]
役に立ちましたか?

解決

-(void)inputAccessoryViewDidFinish

{
   [self.someInput resignFirstResponder];
}

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

他のヒント

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

This tutorial can get you started.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top