Coming from a Java background, I'm still don't quite understand the semantics of Objective-C methods as opposed to their syntax. Take as an example the following method:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
Easy enough. There is a method named numberOfSectionsInTableView which takes a UITableView as a parameter and returns a NSInteger. Now, how about these methods:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
How should I interpret these methods? I've stumbled upon three possible explanations:
1) All three the methods are named tableView and they are overloaded with different parameters. This seems unlikely as people talk about 'calling the numberOfRowsInSection method'.
2) The methods are named numberOfRowsInSection, heightForRowAtIndexPath and cellForRowAtIndexPath, and the tableView is an artifact due to delegation. In that case, what exactly does the tableView part mean syntactically? If the format of a method is '(return)name:parameters, where does tableView fit in?
3) As Objective-C uses message passing, it's wrong to think about methods. Rather think about passing messages to the object directly. In other words, if the object receives the messages named tableView and numberOfRowsInSection, it knows to execute a certain part of the code. If this is the case, does order matter? Is passing numberOfRowsInSection and tableView the same as passing tableView and numberOfRowsInSection?