I understood before that the Delegate template is used only to call events in a delegate instance and get controls (for example, size / font / etc ...).
Datasource template is intended only for receiving data from a datasource instance (for example, views / title / description / etc ...)
But it looks like it was a good illusion, looking at the Apple UITableViewDelegate protocol , I got confused because
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section; - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;
Are delegate methods (but I thought these were UITableViewDatasource methods)
Is this dirty Apple code, or am I missing something important that also understands the difference between a data source and a delegate?
EDIT: Thanks @DBD for the nice answer, there is more confusion here
Here is a UITableViewDelegate method that returns View for drawing
- (UIView *) tableView: (UITableView *) tableView viewForHeaderInSection: (NSInteger) section;
And also there is a configuration in UITableViewDataSource
- (NSString *) tableView: (UITableView *) tableView titleForHeaderInSection: (NSInteger) section;
And unfortunately, we can see a method that returns a view in a UITableViewDataSource
- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath;
This begs the question why cellForRowAtIndexPath: and viewForHeaderInSection: not in UITableViewDataSource
design ios objective-c uikit uitableview
l0gg3r
source share