2010-02-27 12 views
9

Quiero encontrar una forma de activar mediante programación el selector que hace que el teclado del iPhone cambie de letras a números. Soy consciente de que puedo cambiar el tipo de teclado, pero quiero saber si hay una forma de hacerlo sin cambiar el tipo de teclado.¿Puedo disparar mediante programación el botón "cambiar al teclado numérico" en el teclado del iPhone

+0

es esto para UIWebView o alguna otra subclase de UIView? EDITAR: Perdón, ¿acabo de notar que la etiqueta uitextfield – conorgriffin

Respuesta

6

No puede cambiar los planos de teclas (plano de teclas alfabético a plano de teclas numérico a plano de símbolos) programáticamente, al menos no de forma pública. Como mencionaste, puedes cambiar el tipo de teclado o la apariencia de los rasgos de entrada de texto del primer respondedor, pero esto es diferente a cambiar entre los diferentes teclados, que solo el usuario debería poder hacer.

1

Tener un vistazo a esto:

- (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; 

} 

comprobar dónde os comento "c este cuidado totalmente"

Esto le ayudará a cambiar de teclado mediante programación.

+0

puede corregir la sangría en su código? – rickharrison

6

Sólo una solución: Cuando se desea cambiar el keyplane de un teclado activo como del alfabeto para teclado numérico mientras se edita un UITextField, primero ajuste el nuevo valor a la propiedad KEYBOARDTYPE del campo de texto, junto enviar un resignFirstResponder, finalmente, un mensaje de becomeFirstResponder para el campo de texto. P.ej.

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

Swift:

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

Espero que ayuda ;-D

+0

¿Alguna palabra sobre aplicaciones que son rechazadas por hacer esto? –

+2

¡Use 'textField.reloadInputViews()' en su lugar! –

+0

@NikKov 'textField.reloadInputViews()' no funciona por sí mismo. – David

Cuestiones relacionadas