Isaac
Isaac

Reputation: 1890

How to programmatically avoid iPhone/iPad addition of a '.' char into textfields when typing 2 consecutive spaces?

When I type two or more consecutive space chars into an iPhone/iPad textfield, iOS adds a '.' char at the end of the last typed word, which is something I don't usually want. I think I've disabled all kind of "automatic correction controls" for my textfields inside Interface Builder, but no luck.

Upvotes: 0

Views: 341

Answers (1)

GeekyPunk
GeekyPunk

Reputation: 11

In this method:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)

instead of return YES do this:

return !(range.location > 0 && 
             [string length] > 0 &&
             [[NSCharacterSet whitespaceCharacterSet] characterIsMember:[string characterAtIndex:0]] &&
             [[NSCharacterSet whitespaceCharacterSet] characterIsMember:[[textField text] characterAtIndex:range.location - 1]]);

}

Upvotes: 1

Related Questions