UITextField 内をクリックすると、ピッカーが表示されます。これは私のコードです(動作します):
[super viewDidLoad];
// Picker View dei Tipi
pickerTipo= [[UIPickerView alloc] init];
pickerTipo.showsSelectionIndicator = YES;
UIToolbar* keyboardDoneButtonView = [[UIToolbar alloc] init];
[keyboardDoneButtonView sizeToFit];
UIBarButtonItem* doneButton = [[UIBarButtonItem alloc]
initWithTitle:
@"Fine" style:UIBarButtonItemStyleBordered
target:self
action:@selector(pickerDoneClicked:)];
[keyboardDoneButtonView setItems:[NSArray arrayWithObjects:doneButton, nil]];
self.textTipo.inputAccessoryView = keyboardDoneButtonView;
[self.textTipo resignFirstResponder];
self.textTipo.inputView = pickerTipo;
self.textTipo.delegate = self;
ピッカーとアクセサリ ビューが正しく表示されます。問題は、UITextField がまだ編集可能であることです。つまり、UITextField 内にまだ入力できます。ピッカーが表示されているときは、UITextField 内で編集を有効にしないでください。
[解決済み] 受け入れられた回答に続いて、正しいコードは次のとおりです。
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if (textField == self.textTipo || textField == self.textStato)
return NO;
else
return YES;
}