1

I know that Objective-C does not support method overloading. However, how can I understand the following delegate methods with the same name as 'tableView'? To me, those methods seem to be overloading ones, but I am not sure.

For a view controller to indicate that it is a UITableView delegate, it must implement the UITableViewDelegate protocol. The following are common delegate methods to implement in the view controller:

tableView:heightForRowAtIndexPath:
tableView:willDisplayCell:forRowAtIndexPath:
tableView:didSelectRowAtIndexPath:
tableView:didDeselectRowAtIndexPath:
tableView:commitEditingStyle:forRowAtIndexPath:
tableView:canEditRowAtIndexPath:
Carl Veazey
  • 18,392
  • 8
  • 66
  • 81
user1219702
  • 201
  • 1
  • 4
  • 12
  • 5
    Those are all different. The entire string, including the ':' and everything following is part of the method/selector name. – Mike Weller Jan 18 '13 at 16:59

1 Answers1

7

All the methods you list are different, because the selector name includes all the parts, not just the part up to the first colon ':'.

Here is an example of attempted method overloading in Objective C (which the compiler will reject):

- addSomething:(NSObject *) toView:(UIView *)view
- addSomething:(UIView *) toView:(UIView *)view   // won't work

Note that you are allowed to 'overload' a method when there is a class method and an instance method variant with the same name:

- addSomething:(NSObject *) toView:(UIView *)view 
+ addSomething:(NSObject *) toView:(UIView *)view  // this is OK

Obviously you'd want quite a good reason to do something potentially confusing like this!

See also this question:

Class method and instance method with the same name in Objective-C

Community
  • 1
  • 1
occulus
  • 16,959
  • 6
  • 53
  • 76
  • Thank me by accepting my answer please. click on the tick to the left of the answer, it should go green. – occulus Jan 20 '13 at 17:38