views:

153

answers:

1

I have a textfield and a label.

When you touch the textfield, the keyboard appears

In IB, the textfield's properties are

Keyboard: ASCII Capable Return Key: Done

I wired the IBOutlet to the label and the textfield.

How do I get the keyboard to go away when I'm done entering text. How do I get to copy the text to the UIlabel?

thanks

+1  A: 

If you push the DONE Button, the UITextField sends a -textFieldDidEndEdititing: method to its delegate, which should be your controller instance.

This method simply moves the editor focus off the UITextField and thus makes the keyboard disappear. Then put the new values into the UILabel:

-(void)textFieldDidEndEditing:(UITextField *)textField {
    [textField resignFirstResponder];
    label.text = textField.text;
}
Ralf Edmund
How do I make a delegate? I don't think I've assigned a delegate.
Cocoa Dev
The `delegate` is a property/outlet on the `UITextField` instance. Simply connect this outlet using the InterfaceBuilder with your controller instance which is normally represented by the "Files Owner" instance in the .XIB file.
Ralf Edmund