Giablo
Giablo

Reputation: 203

Objective C delegate - why specify an instance in the first part of function definition?

I'm confused as to what the first part of the following function declaration means. It adds an object instance as part of the function definition.

E.g. In some sample code, class ItemsViewController which derives from UITableViewController has this function definition:

-(void) tableView:(UITableView*) aTableView didSelectRowAtIndexPath:(NSIndexPath*) indexPath
{ ... }

What exactly does the tableView:(UITableView*) aTableView bit achieve?

Upvotes: 1

Views: 177

Answers (1)

David
David

Reputation: 2871

It allows your delegate to serve as the delegate for multiple UITableViews. When an event happens on any of the UITableViews, the appropriate delegate method gets called and you can use the first parameter to determine which UITableView the event relates to, and act accordingly. (Of course, your delegate has to have some way of knowing which view is which, for instance by having outlets to each of the views that it's the delegate for.)

Upvotes: 6

Related Questions