开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜