How do I create or appoint a delegate?

How do I make a delegate? I have a class called CustomSign. The class has a view associated with it. A view has 2 elements. Text box and uilabel. I want to copy text field data to uilabel when you click Finish.

Here is my code in CustomSign.m I do not know how to make it a delegate.

-(void)textFieldDidEndEditing:(UITextField *)textField {
    [textField resignFirstResponder];
    label.text = textField.text;
}
+3
source share
1 answer

You need to have a link to the text box in your file CustomSign.m. This can be either an output, which you then connect to Interface Builder, or you can directly refer to a text field if you create it programmatically.

-setDelegate: , :

//in CustomSign.m
- (void)awakeFromNib
{
    //assume textField is an ivar that is connected to the textfield in IB
    [textField setDelegate:self];
}

Interface Builder .

, -resignFirstResponder .

+7

Source: https://habr.com/ru/post/1742051/


All Articles