Why are some method declarations in the UITableViewDataSource protocol preceded by tableView: (UITableView *) tableview?

The wording of the question can be confusing. I understand why it is useful that the method seems to cellForRowAtIndexPathget a pointer to the corresponding UITableView.

What I donโ€™t understand is more Objective-C wise: I would like to specify a name on this special method declaration method?

It is as if an object (for example, UITableView) that has some internal protocol (for example, UITableViewDataSource) sent messages to developers using a special way of referring to itself.

those. Instead of passing a reference to itself as a regular argument to an Objective-C message, does UITableView use this special syntax?

+1
source share
1 answer

Edit

The comments on this answer have a rather lengthy discussion, which clarifies the original question. I will post the highlights here to help others who may have similar questions.

It came down to a confusion between the two methods,

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

The first method is an instance method UITableViewthat returns UITableViewCellfor a given pointer path. This method is called on the table view object.

The second method is a data source method declared in the protocol UITableViewDataSource, which requests UITableViewCellfor a given pointer path.

, , , , .

, .


/ Cocoa/Cocoa Touch . - " ".

. , , . , , .

, , , , / , . UITableView , , , , .

+4

Source: https://habr.com/ru/post/1746649/


All Articles