How do I make a delegate? I have a class called CustomSign. The class has a view associated with it. The view has 2 elements. A textfield and a uilabel. I want to copy the textfields data to the uilabel when you click the done button.
Here’s my code in the CustomSign.m
I don’t know how to make it a delegate.
-(void)textFieldDidEndEditing:(UITextField *)textField {
[textField resignFirstResponder];
label.text = textField.text;
}
You need to have a reference to the text field in your
CustomSign.mfile. This can either be an outlet which you then connect up in Interface Builder, or you can store a reference to the text field directly if you’re creating it programmatically.You then call the
-setDelegate:method of the text field to assign your object as the delegate:You can also set the delegate of the text field in Interface Builder by control-dragging from the text field to your object.
Note that you should not call
-resignFirstResponderyourself.