Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Delegate and Delegate Methods

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

like image 906
user185590 Avatar asked Nov 24 '09 05:11

user185590


People also ask

What is delegate with example?

Delegates can be used to define callback methods. Delegates can be chained together; for example, multiple methods can be called on a single event. Methods don't need to match the delegate signature exactly. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object.

How do you use the delegate method?

You can pass methods as parameters to a delegate to allow the delegate to point to the method. Delegates are used to define callback methods and implement event handling, and they are declared using the “delegate” keyword. You can declare a delegate that can appear on its own or even nested inside a class.

What is in delegate?

A delegate is a person who is chosen to vote or make decisions on behalf of a group of other people, especially at a conference or a meeting.

What is a delegate explain types of delegates?

Definition. A delegate(known as function pointer in C/C++) is a references type that invokes single/multiple method(s) through the delegate instance. It holds a reference of the methods. Delegate types are sealed and immutable type.


1 Answers

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?

like image 72
Daddy Avatar answered Oct 08 '22 02:10

Daddy