I am getting strange behaviour from UISearchBar. When I press more that one space in UISearchBar, it automatically puts full stop “.” in search bar text. I do not understand why this is happening. Here is my code,
NSString *str = [searchBar.text stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSLog(@"%@",searchBar.text );
I press space and then f and then 2 times space and it puts full stop. Please help me.
Thanks in advance.
This is a property of iOS, not the UISearchBar element.
It is configurable as ” ‘.’ Shortcut” in General -> Keyboard in the Settings part of iOS. It’s description: “Double tapping the space bar will insert a period followed by a space.”
As for programmatically removing the period/full stop, i guess you could do that with regexes, but I wouldn’t recommend it. Because the feature is part of the user preferences for the keyboard, it will act the same, no matter what app you are using. It’s kind of like changing all the text that the user types to uppercase, they may not want it that way (or they may be used to double tapping shift), so your app becomes confusing and hard to use.
I would say just leave it as is.