Search code examples
objective-cunicodeios6xcode4.5core-text

looking for getchar() program


This is my first post ever on stack OF... Toying with iOS and am looking to mirror back text input as similar to K&R 1.5.1:

main()
{
    int c;
    c = getchar();
    while (c != EOF) {
        putchar(c);
        c = getchar();
    }
}

FWIG the built in deal is to use the text input but that gives me an entire string, and I need to process the input one character at a time (and input from a different language at that)


Solution

  • I'm afraid you do have to use the UIKit route. If you want the changed characters, implement the UITextFieldDelegate delegate in your controller and implement the textField:shouldChangeCharactersInRange:replacementString: method which is called for every changed character. Note though that it might be called on a range of characters, ie when the user deletes a range or tries to paste something (you can return NO in that case and only accept single character changes at the end of the input, but that breaks the expected behaviour of the user interface, which might or not be okay in your case, depending on what you are trying to achieve)