0

我在一个 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];
}

这是一个相当直截了当的问题,我通常使用这种技术与基本视图和文本字段来解除键盘没有问题。我不确定是否使用这种演示格式的视图或设置会使事情变得不同。谢谢!

4

2 回答 2

0

看看这个问题。很确定这是由 UIModalPresentationFormSheet 引起的相同问题。

于 2013-01-10T12:45:41.280 回答
0

您已经确认您的 keyboardEndOnExit 方法实际上正在被调用?

您还可以通过调用 [yourTextView resignFirstResponder] 来采取更直接的方法,当用户采取特定操作时,例如按下键等。我仍然会检查是否曾经使用断点或日志调用该方法。

于 2011-11-01T17:41:32.223 回答