iPhone SDK: disable auto creation of dot (.) in text field (or textview)

后端 未结 2 783
一整个雨季
一整个雨季 2020-12-19 12:28

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 spac

相关标签:
2条回答
  • 2020-12-19 13:11

    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:@" "];
      }
      }

    0 讨论(0)
  • 2020-12-19 13:35

    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 @". "

    0 讨论(0)
提交回复
热议问题