如何创建或分配代理人?
我如何指定代表?我有一个名为 CustomSign 的课程。该类有一个与其关联的视图。该视图有 2 个元素。一个文本字段和一个 uilabel。当您单击“完成”按钮时,我想将文本字段数据复制到 uilabel。
这是我在 CustomSign.m 中的代码 我不知道如何使其成为代表。
-(void)textFieldDidEndEditing:(UITextField *)textField {
[textField resignFirstResponder];
label.text = textField.text;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要引用
CustomSign.m
文件中的文本字段。这可以是您随后在 Interface Builder 中连接的插座,也可以直接存储对文本字段的引用(如果您以编程方式创建它)。然后,您可以调用文本字段的
-setDelegate:
方法将您的对象指定为委托:您还可以在 Interface Builder 中通过按住 Control 键将文本字段拖到您的对象上来设置文本字段的委托。目的。
请注意,您不应自己调用
-resignFirstResponder
。You need to have a reference to the text field in your
CustomSign.m
file. 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
-resignFirstResponder
yourself.