Created
April 19, 2013 15:15
-
-
Save vixentael/5421028 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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