我在一个 viewController 上创建了一个按钮,该按钮使用 UIModalPresentationFormSheet 演示样式以模态方式加载另一个视图。在这个加载的视图上,我有两个文本字段,我强制第一个文本字段成为第一响应者,以便键盘将立即出现在新视图中。我已将 textFields 设置为具有与“Did End on Exit”事件相关联的操作方法。但是,每当我为任一文本字段在键盘上按“返回”时,键盘都无法消失(这是我的代码):
// 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];
}
这是一个相当直截了当的问题,我通常使用这种技术与基本视图和文本字段来解除键盘没有问题。我不确定是否使用这种演示格式的视图或设置会使事情变得不同。谢谢!