IPhone SDK: disable the automatic creation of points (.) In the text box (or text view)

I turned off the automatic correction type for my text box, and it does not show any other auto correction,

but it still automatically creates a period (.) when I press the spacebar twice.

For example, if I write β€œtest” and press the space bar twice, it automatically goes into β€œtest”.

Does anyone know how to disable this feature?

Many thanks.

+4
iphone autocomplete cocoa-touch sdk
source share
2 answers

I found one solution - it uses UITextFieldTextDidChangeNotification, because it happens after applying automatic correction.

  • Set delegate for text field
  • Set notification

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

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

+2
source share

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

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

You can check aString for an auto-corrected string (maybe @ ".") And then just return NO. This, we hope, will not allow @ "replace with @".

+1
source share

All Articles