27

I want to change keyboard type from default to numeric after user pressed return button. However after setting keyboardType property nothing happens.

My code:

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];

    return YES;
}

I have set myself as text field delegate and the method is being called after pressing return button.

EDIT: Solved by

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];
    [textField reloadInputViews];
    return YES;
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Kladimir
  • 317
  • 1
  • 3
  • 11
  • http://stackoverflow.com/questions/7301018/programmatically-change-uitextfield-keyboard-type – Rushabh Sep 27 '12 at 10:40
  • You might want to try the solution posted in this question: http://stackoverflow.com/questions/1594346/dynamically-changing-keyboard-type-for-a-uisearchbar – henning77 Sep 27 '12 at 10:52
  • Possible duplicate of [Programmatically change UITextField Keyboard type](https://stackoverflow.com/questions/7301018/programmatically-change-uitextfield-keyboard-type) – Parth Patel Jul 11 '19 at 09:50

2 Answers2

27

Try this:

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];
    [textField reloadInputViews];
    return YES;
}
pro_metedor
  • 1,176
  • 10
  • 17
  • @Kladimir if any answer helps and perfectly answers your question you should mark it as accepted using the correct sign below the answer points and vote arrows. – Himanshu A Jadav Sep 27 '12 at 11:01
0

You can do this in the Text Input Traits section under the Attributes inspector.

Muhammad Zaheer
  • 123
  • 1
  • 10