5

I've disabled auto-correction type for my text field, and it does not show any other auto-correction,

but it still automatically creates a dot (.) when I press space key twice.

For example, if I write "test" and press space key twice, it automatically changes into "test. "

Anyone knows how to disable this feature?

Thanks a lot.

Will Yeo - MSFT
  • 231
  • 1
  • 3
  • 7

2 Answers2

2

I found one solution - it uses UITextFieldTextDidChangeNotification because this occurs after the auto-correction applies.

  1. Set the delegate for the text field
  2. Set up a notification

    - (void) viewDidLoad {
    ...
    [[NSNotificationCenter defaultCenter] addObserver:self
    selector:@selector(textFieldDidChange:)
    name:UITextFieldTextDidChangeNotification object:tfTitle];
    }

  3. Then, notification handler
    - (void)textFieldDidChange:(NSNotification *)aNotification
    {
    if ( [textField.text rangeOfString:@". "].length ) {
    // Change text
    textField.text = [textField.text stringByReplacingOccurrencesOfString:@". " withString:@" "];
    }
    }

Will Yeo - MSFT
  • 231
  • 1
  • 3
  • 7
1

Perhaps if you hook up a text field delegate and then implement the following method:

-(BOOL)shouldReplaceCharactersInRange:(NSRange)aRage withString:(NSString *)aString

You may be able to check aString for the autocorrected string (maybe @". ") and then just return NO. This will hopefully not allow the @" " to be replaced with @". "

Michael Waterfall
  • 20,497
  • 27
  • 111
  • 168
  • Hi Bisbo, I tried your suggestion, and found that the auto-correction (double tap of space into period) occurs after this method is called, and the change does not call this method to check. Thanks anyway, and please let me know if you have any other idea. – Will Yeo - MSFT Oct 07 '09 at 03:23
  • Ahh, oh well, was just a thought :-) – Michael Waterfall Oct 07 '09 at 14:02
  • 1
    That works if you check for double spaces, see that one: http://stackoverflow.com/questions/2576561/iphone-disable-the-double-tap-spacebar-for-shortcut/3023716#3023716 – Vincent Guerci Mar 21 '11 at 21:28