2012-08-29 79 views
1

我有我的自定义键盘设置。我有按钮创建。但是,如何将按下的值传递给它,就好像它是普通的键盘一样?自定义键盘发送输入到文本框

例如,如果点击我标签为“1”的按钮,我想将其发送到具有我的自定义输入的uitextfield,因为它的inputView或任何文本字段是使用我的自定义键盘的第一响应者。

我敢肯定,这是简单的...

+0

我知道我可以分配的UITextField到我的自定义键盘,但我是真的很好奇是iPhone的键盘如何通过它的输入。当然,必须有一个简单的委托方法或什么? – Hackmodford

+0

UITextInput协议是你在找什么? –

回答

0

试试这个:

UITextField textfield; //your textfield 

- (void) whenButtonIsClicked{ 
    textfield.text = [NSString stringWithFormat:@"%@%@", textfield.text, NEW_CHARACTER_FROM_BUTTON_CLICK]; 
} 
0

您的自定义键盘有一个代表还是应该有对您的自定义键盘视图按钮按下,不是招”委托它呢? 如果是这样,一个按钮按下示范委托实施看起来是这样的,对于一个自定义的数字键盘,例如:

- (void) customKeyboardView: (YourCustomKeyboardView*) customKeyboardView didTapButtonAtIndex: (NSUInteger) index { 
    if (index == 9) { 
     // Tapped empty button 
    } else if (index == 11) { 
     // Back Button Tapped 
     NSString* input = self.yourTextField.text; 
     if ([input length] > 0) 
      self.yourTextField.text = [input substringToIndex: [input length] - 1]; 
    } else { 
     self.yourTextField.text = [NSString stringWithFormat:@"%@%@", self.yourTextField.text, [self titleForButtonAtIndex: index]]; 
    } 
}