Skip to content

Instantly share code, notes, and snippets.

@vixentael
Created April 19, 2013 15:15
Show Gist options
  • Save vixentael/5421028 to your computer and use it in GitHub Desktop.
Save vixentael/5421028 to your computer and use it in GitHub Desktop.
@implementation CHVariableHeightDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGFloat height = tableView.rowHeight;
id object = [(NITableViewModel *)tableView.dataSource objectAtIndexPath:indexPath];
// cell class
id class = nil;
if ([object respondsToSelector:@selector(cellClass)]) {
class = [object cellClass];
} else {
// Trying to resolve cell class from model->cellFactory
NITableViewModel * model = [(NSObject * )tableView.dataSource castOrNil:[NITableViewModel class]];
NICellFactory * cellFactory = [(NSObject * )[model delegate] castOrNil:[NICellFactory class]];
if (cellFactory) {
NSDictionary * mapping = [cellFactory valueForKey:@"objectToCellMap"];
class = [mapping objectForKey:[object class]];
}
}
if ([class respondsToSelector:@selector(heightForObject:atIndexPath:tableView:)]) {
height = [class heightForObject:object atIndexPath:indexPath tableView:tableView];
}
return height;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment