【问题标题】:Activating the iphone keyboard激活 iphone 键盘
【发布时间】:2010-06-30 10:07:08
【问题描述】:

我不敢相信我还没有找到任何关于此的文档,但我想知道如何命令键盘激活并从中接收输入。我能找到的所有示例都可以在哪里操作由于正在编辑文本字段而弹出的键盘。谢谢

【问题讨论】:

  • 这就是您激活键盘的方式。如果您想以编程方式显示它,请制作一些具有 UIKeyboardTraits(或其他任何名称)的控件作为第一响应者和键盘将显示。
  • Jason,你应该重新输入这个作为答案

标签: iphone cocoa-touch keyboard


【解决方案1】:

您还可以使用 UIKeyInput 协议来请求键盘,而无需创建隐藏文本字段。

@interface My : UIViewController <UIKeyInput> ...

然后在实现中是这样的

// Methods which make the keyboard work

- (BOOL) hasText
{
    return YES;
}

- (void)deleteBackward
{
    [self handleBackspace];
}

- (void) insertText:(NSString* )text
{
    int n = [text length];
    int i;
    for (i = 0; i < n; i++)
    {
        [self handleKey:[text characterAtIndex:i]];
    }
}

- (BOOL) canBecomeFirstResponder
{
    return YES;
}

// Methods to manage the appearance of the keyboard

- (void) summonKeyboard
{
    [self becomeFirstResponder];
}

- (void) dismissKeyboard
{
    [self resignFirstResponder];
}

【讨论】:

  • 有效吗?遵循UIKeyInput 协议UIViewcontroller
【解决方案2】:

我最终决定创建一个隐藏在视图中的文本字段,并由以下人员选择:

[text_input becomeFirstResponder];

【讨论】:

    猜你喜欢
    • 2021-08-29
    • 1970-01-01
    • 2013-08-16
    • 2012-09-21
    • 1970-01-01
    • 2016-10-11
    • 2015-06-12
    • 2015-03-27
    • 1970-01-01
    相关资源
    最近更新 更多