Let\'s say I have the following code:
IBOutlet UITextField* nameTextField;
IBOutlet UILabel* greetingLabel;
I\'d like the greetingLab
UITextField
has a notification UITextFieldTextDidChange
which will be fired every time the text changes if you register for it. Just register for that notification and in the method called by the notification, change the label's text.
To add to this, the object passed to your notification handler will have the text of the UITextField
.
Hope that helps.
you could register an action for the event UIControlEventEditingChanges on the text field:
[nameTextField addTarget:self action:@selector(updateLabelUsingContentsOfTextField:) forControlEvents:UIControlEventEditingChanged];
...
// TODO: error checking
- (void)updateLabelUsingContentsOfTextField:(id)sender {
greetingLabel.text = [NSString stringWithFormat:@"Hello %@", ((UITextField *)sender).text];
}
It turns out, the easiest way to do this is using Interface Builder:
Works like a charm :) (I can't believe I spent numerous days on this, and to realize now that the solution was much simpler than I'd thought :P)