おそらく、 (または同様のコントロール)のinputAccessoryView
プロパティを使用する必要があります。UITextField
ドキュメントから:
このプロパティのデフォルト値は nil です。システム提供の入力ビュー (キーボードなど) またはカスタム入力ビュー (inputView プロパティで提供するもの) にカスタム コントロールをアタッチするサブクラスは、このプロパティを readwrite として再宣言し、それを使用してカスタム アクセサリ ビューを管理する必要があります。 . その後、レシーバーがファーストレスポンダーになると、レスポンダー インフラストラクチャはビューを表示する前に適切な入力ビューにアタッチします。
これが私のアプリの1つからのサンプルコードです:
// Adding a UIToolbar on top of the keyboard
UIToolbar* keyboardDoneButtonView = [[UIToolbar alloc] init];
keyboardDoneButtonView.tintColor = nil;
keyboardDoneButtonView.barStyle = UIBarStyleBlack;
keyboardDoneButtonView.translucent = YES;
[keyboardDoneButtonView sizeToFit];
// Done button on the left
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(editingDone:)];
doneButton.tintColor = TINT_COLOR;
// Creating a flexible space so the button is on the right side
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
// Creating the Next button on top of the keyboard
UISegmentedControl *saveButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Previous", @"Next", nil]];
saveButton.momentary = YES;
saveButton.frame = CGRectMake(260, 7.0f, 120.0f, 30.0f);
saveButton.segmentedControlStyle = UISegmentedControlStyleBar;
saveButton.tintColor = [UIColor blackColor];
[saveButton addTarget:self action:@selector(moveToNextOrPrevious:) forControlEvents:UIControlEventValueChanged];
saveButton.tag = indexPath.row;
// You have to encapsulate the SegCtrl in a bar button item for it to work
UIBarButtonItem *segCtrlEnc = [[UIBarButtonItem alloc] initWithCustomView: saveButton];
// Adding the toolbar with elements
[keyboardDoneButtonView setItems:[NSArray arrayWithObjects: segCtrlEnc, flexibleSpace, doneButton, nil]];
// Plug the keyboardDoneButtonView into the text field...
cell0tf.textField.inputAccessoryView = keyboardDoneButtonView;
編集: コードは説明を目的としたものです。アプリにコピー アンド ペーストするだけでは、すぐには機能しない可能性があります。