How can I detect and respond when the return key is pressed using the UIKeyInput protocol?
I have a table view that displays a list that I want the user to be able to edit. To save space and make it easier to see on my eyes, I created a dedicated toolbar that follows the UIKeyInput protocol so that I can pull up the keyboard without using any text boxes. So far, so good. I have a mutable string that handles keyboard input:
- (void)insertText:(NSString *)text {
if (!itemForList) {
itemForList = [NSMutableString string];
}
[itemForList appendString:text];
}
What I can't figure out how to do is detect when the user hits the back button. This is important because I need to be able to enter the string the user was typing and add it to the mutable array displayed by the table view and then reset the string to handle the new input. I would really appreciate any help in this area. Thanks guys.
+3
source to share
1 answer
Have you tried using escape characters? Example:
- (void)insertText:(NSString *)text {
if ([text isEqualToString:@"\n"]) {
//do whatever you want to do when user taps the return key
}
if (!itemForList) {
itemForList = [NSMutableString string];
}
[itemForList appendString:text];
}
Hope it helps
+2
source to share