开发者

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

开发者 https://www.devze.com 2023-01-10 09:52 出处:网络
I\'m confused as to what the first part of the following function declaration means. It adds an o开发者_开发知识库bject instance as part of the function definition.

I'm confused as to what the first part of the following function declaration means. It adds an o开发者_开发知识库bject 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?


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消