什么是委托和委托方法 [英] What is Delegate and Delegate Methods

查看:28
本文介绍了什么是委托和委托方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都请告诉我代表和代表之间的区别委托方法及其区别和用法???

Guys anyone please let me know difference between Delegate & Delegate Methods and its differences and its usages ???

推荐答案

很难解释,但是委托代表另一个对象执行方法.当您在列表中选择一个项目时,表视图不知道该做什么.相反,它必须向委托对象询问一个问题,特别是 didSelectRowAtIndexPath.tableview 知道的唯一信息是用户点击了哪个部分和行.因此,表格视图通过本质上说嘿,用户在第 0 节中点击了第 4 行.做某事"来向委托对象提供此信息.

It's hard to explain, but a delegate performs methods on behalf of another object. A Table View doesn't know what to do when you pick an item in the list. Instead, it has to ask the delegate object a question, specifically, didSelectRowAtIndexPath. The only information the tableview knows is which section and row the user tapped. So the table view gives this information to the delegate object by essentially saying that "Hey, the user tapped Row 4 in Section 0. Do something."

委托对象找到didSelectRowAtIndexPath方法并执行里面的代码.

The delegate object finds the didSelectRowAtIndexPath method and executes the code inside.

对于许多不同的对象,有许多 Delegate 方法.例如,Text Field 对象不能自己做任何事情.相反,它使用委托来执行操作.如果您按下屏幕键盘上的 Enter 键,文本字段会要求委托对象执行特定方法 textFieldShouldReturn.如果您为文本字段设置的委托没有 textFieldShouldReturn 方法,那么当您按下回车按钮时,文本字段将不知道该做什么.

There are lots of Delegate methods for many different objects. For instance, the Text Field object can't do anything on its own. Instead, it uses a delegate to perform actions. If you press the enter key on the on screen keyboard, the text field asks the delegate object to perform a specific method, textFieldShouldReturn. If the delegate you set for your text field does not have a textFieldShouldReturn method, the text field will not know what to do when you press the enter button.

这有意义吗?

这篇关于什么是委托和委托方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆