3

I have a table view that displays a list that I want the user to be able to edit. In order to save space, and to make my view easier on the eyes, I have created a custom toolbar that conforms to the UIKeyInput protocol so that I can pull up a keyboard without having to use any text fields. So far so good. I have a mutable string that is handling the input from the keyboard:

- (void)insertText:(NSString *)text {
    if (!itemForList) {
        itemForList = [NSMutableString string];
    }    
    [itemForList appendString:text];

}

The thing that I can't figure out how to do is detect when the user presses return. This is important because I need to be able to take the string that the user typed in and add it to the mutable array that the table view is displaying from, and then reset the string to handle new input. I would greatly appreciate any help in this field. Thanks guys.

Sam Hazleton
  • 470
  • 1
  • 5
  • 21
  • 1
    Hazelton, welcome to StackOverflow. I'm sure you didn't realize but you shouldn't change a question to a completely new question. Your original question seems to have been answered and that answer accepted(correctly). If you have a different related question please post another question and possibly link to this one for context. The original question should be restored so it can help others. – NJones Mar 07 '12 at 03:07
  • thanks, i would love to restore it. is there any way i can recover a past draft, or will I have to just do the best i can to remember what I posted? – Sam Hazleton Mar 07 '12 at 23:22

1 Answers1

5

Did try 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

Novarg
  • 7,390
  • 3
  • 38
  • 74
  • I hadn't tried that, I just thought of testing it with the ascii code and i wrote it in but haven't tested it yet. if it doesn't work i will try it that way. – Sam Hazleton Mar 06 '12 at 22:33
  • I actually have a related question: I have used table views with keyboards before, and I have always used the NSNotificationCenter to detect when keyBoardDidShow or KeyBoardWillHide. For some reason the same code will not work in this case. I tried it with the ViewController as the observer and then with the toolbar that brings up the keyboard as the observer, and neither seems to work. – Sam Hazleton Mar 06 '12 at 22:58
  • @SamHazleton if you would provide some code on how do you work with these cells and how does the keyboard appear I might be able to help you. And please upvote the answer :) – Novarg Mar 06 '12 at 23:19
  • edited my question to reflect new data. wouldn't let me up vote your answer, sorry – Sam Hazleton Mar 06 '12 at 23:52
  • I actually just asked a completely new question that includes this second problem. If you would like to take a look at it I would appreciate it. [link](http://stackoverflow.com/q/9610454/1227207) – Sam Hazleton Mar 07 '12 at 23:28
  • my deletebackward and insertText methods are not getting called in the subclass. Any help ? – nr5 Oct 18 '13 at 07:20