views:

19

answers:

1

I am very new to this and i am sorry to ask this question.

I am trying to get this to work for my code but just don't get it. Whatever i seems to do the key that i press show up in the NSLog one key stroke after. I know that the 'shouldChangeCharactersInRange' works this way and i have surfed and tried to test some solutions i have found. One is: http://stackoverflow.com/questions/2198067/using-textfieldshouldchangecharactersinrange-how-do-i-get-the-text-including-t but i still just don't get it.

my current test code after i have tried to get it to work and changed it back:

-(BOOL) textField: (UITextField *)theTextField shouldChangeCharactersInRange: (NSRange)range replacementString: (NSString *)string {
    NSLog(@"%@", MyTextField.text);

    MyTextField.text = MyTextField.text;

   return YES;
}

MyTextField is the textfield i type into.

Could someone nice show me how to get this work so i can track each keystroke when it happens and not the keystroke after?

A: 

To see the key that was just pressed, use:

NSLog(@"%@", string);

Technically, this could be more than one character, like with a cut, paste, or undo operation.

The value of the text field doesn't actually change until after the method completes. If you want to see what the value of the text field will be, use

NSLog(@"%@", [MyTextField.text stringByReplacingCharactersInRange:range withString:string);
Robot K
Thank you very much, that made the trick :-)
PeterK