UIModalPresentationFormSheet プレゼンテーション スタイルを使用してモーダルに別のビューを読み込む 1 つの viewController にボタンを作成しました。このロードされたビューには 2 つの textField があり、最初の textField をファーストレスポンダーにして、新しいビューでキーボードがすぐに表示されるようにします。「Did End on Exit」イベントに接続されるアクション メソッドを持つように textFields を設定しました。ただし、いずれかの textField のキーボードで「return」を押すたびに、キーボードが消えません (ここに私のコードがあります)。
// addCustomPage method that is called when button from original view is touched
- (IBAction) addCustomPage:(id)sender
{
NSLog(@"Adding Custom Page");
if (!self.customPageViewController)
{
self.customPageViewController =
[[CustomPageViewController alloc] initWithNibName:@"CustomPageViewController" bundle: nil];
}
customPageViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:customPageViewController animated:YES];
// force keyboard to appear with loaded page on the first textField
[customPageViewController.firstTextField becomeFirstResponder];
}
@interface CustomPageViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *firstTextField;
@property (strong, nonatomic) IBOutlet UITextField *secondTextField;
- (IBAction)keyboardEndOnExit:(id)sender; // DID END ON EXIT EVENT
@end
//in CustomPageViewController.m
-(IBAction)keyboardEndOnExit:(id)sender
{
[sender resignFirstResponder];
}
これはかなり単純な問題であり、基本的なビューと textFields でこの手法を使用してキーボードを閉じるのに問題はありません。このプレゼンテーション形式でビューを使用するか、セットアップすることで状況が変わるかどうかはわかりません。ありがとう!