什么是代表和委托方法 [英] What is Delegate and Delegate Methods
问题描述
很难解释,但代表执行方法代表另一个目的。当您在列表中选择项目时,表视图不知道该怎么办。相反,它必须向委托对象询问一个问题,具体来说是didSelectRowAtIndexPath。 tableview知道的唯一信息是用户点击的部分和行。因此,表视图通过基本上说嘿,用户在第0部分中点击了第4行。执行某些操作,将该信息提供给委托对象。
委托对象查找didSelectRowAtIndexPath方法并在其中执行代码。
许多不同对象有很多Delegate方法。例如,文本字段对象不能自己做任何事情。相反,它使用一个委托来执行动作。如果按屏幕键盘上的回车键,则文本字段将要求委托对象执行特定方法textFieldShouldReturn。如果您为文本字段设置的代表没有textFieldShouldReturn方法,那么当您按Enter按钮时,文本字段将不知道该怎么做。
这是否会感觉?
Guys anyone please let me know difference between Delegate & Delegate Methods and its differences and its usages ???
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."
The delegate object finds the didSelectRowAtIndexPath method and executes the code inside.
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.
Does this make sense?
这篇关于什么是代表和委托方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!