iPhone how to get UITextField's text while typing?

Solution 1:

  1. First add one UITextField and UILabel to storyboard / nib
  2. Now assign IBOutlet for UILabel (Here I have used myLabel)
  3. Assign UITextFieldDelegate to file owner, also implement the same delegate in .h file
  4. Use these lines of code:

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
    {
        NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
        [self updateTextLabelsWithText: newString];
    
        return YES;
    }
    
    -(void)updateTextLabelsWithText:(NSString *)string
    {
         [myLabel setText:string];
    }
    

Hope this helps.

Solution 2:

Simply handle the "Editing Changed" event

[textField addTarget:self 
              action:@selector(editingChanged:)
    forControlEvents:UIControlEventEditingChanged];

and the selector:

-(void) editingChanged:(id)sender {
   // your code
}

You can do this manually, or with the storyboard by CTRL-Dragging the "Editing changed" Sent event to your .h, creating the editingChanged method for you.

Solution 3:

Swift with addTarget Swift 2.0+

   titleTextField.addTarget(self, action: #selector(textFieldTyping), forControlEvents: .EditingChanged)

And implement selector

func textFieldTyping(textField:UITextField)
{
    //Typing
}