iosobjective-cuitextviewuikeyboarduikeyboardtype

iOS change Keyboard type to Twitter when the user taps the '123' keyboard button


I have a UITextView but i do not want the keyboard to provide the user with the 'return' key. So in my xib file i set the keyboard type to UIKeyboardTypeTwitter which basically replaces the 'return' key with the '@' and '#'.

However when tapping the '123' button on the keyboard and thus moving into UIKeyboardTypeNumbersAndPunctuation mode, the 'return' key shows up in the bottom right hand side. Is there a way to detect when the user taps on the '123' and then at that time, keep the '@' and '#' symbols in this situation?


Solution

  • You don’t have enough control over the keyboard for that (and might not even have as much as you think with the UIKeyboardTypeTwitter approach, if the user has a third-party keyboard that works with that); your best option is to detect when they’ve hit Return (via the UITextViewDelegate method -textView:shouldChangeTextInRange:replacementText:) and blocking the newline insertion that way.