Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Forked from anonymous/gist:a4b54bc820ec1bd8bf36
Created December 13, 2012 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukeredpath/e3c9a65769efb9be5a3a to your computer and use it in GitHub Desktop.
Save lukeredpath/e3c9a65769efb9be5a3a to your computer and use it in GitHub Desktop.
@implementation ThingsViewController
static NSString *ThingCellIdentifier = @"ThingCell";
- (ResultSetTableDataSource *)thingsDataSource
{
if (_thingsDataSource == nil) {
_thingsDataSource = [[ResultSetTableDataSource alloc] initWithAutomaticallyUpdatingResultSet:[self.thingsRepository allThings]];
_thingsDataSource.cellIdentifier = ThingCellIdentifier;
_thingsDataSource.changeDelegate = self;
}
return _thingsDataSource;
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView setDataSource:self.thingsDataSource];
}
#pragma mark - ResultSetTableDataSourceChangesDelegate
- (void)dataSource:(ResultSetTableDataSource *)dataSource resultSetDidChange:(NSDictionary *)changes
{
[self.tableView reloadData];
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// Thing *thing = [self.thingsDataSource objectAtIndexPath:indexPath];
// bind conversation object with cell in this method here
}
@end
@andrewsardone
Copy link

I'm interested in why the view controller manages your cell identifier and hands it to the ResultSetTableDataSource. Is this so you can hook into (from the view controller) the iOS 6 API, -[UITableView registerClass:forCellReuseIdentifier:]? Is there some other cell identifier concern beyond cell dequeueing/generation (via -[UITableViewDataSource tableView:cellForRowAtIndexPath:])?

@lukeredpath
Copy link
Author

That's exactly why. The controller is the injection point for registered cells, either via a Storyboards or the registerClass/XIB API. The datasource needs to know the identifier in order to dequeue the right cell, but that's all it needs to know.

@lukeredpath
Copy link
Author

Incidentally, I've since changes my opinion on configuring the cell in the willDisplay method. The documentation was a bit ambiguous but after reading more, Apple do explicitly state elsewhere that the cell should be configured in tableView:cellForRowAtIndexPath: - my solution to this was to give the datasource a configuration block that is called after dequeuing a cell and before returning it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment