2010-02-27 88 views
9

我想找到一种以编程方式触发导致iPhone键盘从字母切换到数字的选择器的方法。我知道我可以切换键盘类型,但我想知道是否有办法在不切换键盘类型的情况下执行此操作。我可以编程方式在iPhone键盘上触发“切换到数字键盘”按钮

+0

是本作的UIWebView UIView的或一些其他子类?编辑:对不起,只是注意到你的代码中可以修改缩进的uitextfield标签 – conorgriffin 2010-02-28 00:24:59

回答

6

您不能以公开支持的任何方式以编程方式切换键盘(字母键盘到数字键盘到符号键盘)。正如您所提到的,您可以更改第一响应者的文本输入特征的键盘类型或外观,但这与在不同的键盘之间切换不同,只有用户应该能够做到。

1

看一看这样的:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString * cellIdentifier = @"CellIdentifier"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
    if(cell == nil) 
    { 
     cell = [ [ [UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease]; 
     cell.textLabel.font = [UIFont boldSystemFontOfSize:14.0f]; 
     cell.textLabel.textColor = [UIColor whiteColor]; 
    } 

    UITextField * textField = [ [ UITextField alloc] initWithFrame:CGRectMake(55.0f, 10.0f, 230.0f, 31.0f)]; 
    textField.textColor = [UIColor whiteColor]; 

    textField.delegate = self; 
c this care fully ///////////if(indexPath.row == 0) 
c this care fully // textField.keyboardType = UIKeyboardTypeDefault; 
c this care fully //else 
c this care fully // textField.keyboardType = UIKeyboardTypePhonePad; 
    textField.autocorrectionType = UITextAutocorrectionTypeNo; 
    [cell.contentView addSubview:textField]; 

    if(indexPath.row == 0) 
    { 
     self.sender = textField; 
     cell.textLabel.text = @"From:"; 
    } 
    else 
    { 
     self.mobileNumber = textField; 
     cell.textLabel.text = @"To:"; 
    } 
    [textField release]; 
    if(indexPath.row == 1) 
    { 
     UIButton * contactsButton = [UIButton buttonWithType:UIButtonTypeContactAdd]; 
     [contactsButton addTarget:self action:@selector(addContact:) forControlEvents:UIControlEventTouchUpInside]; 
     cell.accessoryView = contactsButton; 

    } 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    return cell; 

} 

检查,我评论说:“C这个护理完全”

这将帮助你的键盘编程切换。

+0

? – rickharrison 2010-06-07 14:42:58

6

只是一种变通方法: 当你想在编辑的UITextField活跃键盘的keyplane改变就像从字母到数字键盘,先设置新值文本框的键盘类型物业,未来发送resignFirstResponder,终于成为文本字段的第一个应答消息。例如。

textfield.keyboardType = UIKeyboardTypeNumberPad; 
[textField resignFirstResponder]; 
[textField becomeFirstResponder]; 

斯威夫特:

textField.keyboardType = .numberPad 
textField.resignFirstResponder() 
textField.becomeFirstResponder() 

希望它可以帮助;-D

+0

应用程序上的任何词语因为这样做而被拒绝? – 2011-08-06 21:36:36

+2

改为使用'textField.reloadInputViews()'! – 2016-12-19 05:12:21

+0

@NikKov'textField.reloadInputViews()'本身不起作用。 – David 2017-08-10 17:52:47