From cac1a38e1c163a255d09258e664b0e41b694a477 Mon Sep 17 00:00:00 2001 From: Jason Parekh Date: Thu, 28 Feb 2013 14:49:17 -0500 Subject: [PATCH 1/2] Uncomments height-related methods in ExpandableTableViewDelegate, and adds plumbing to delegate to them. --- ExpandableTableView/Control/ExpandableTableView.m | 10 ++++++++++ .../Control/ExpandableTableViewDelegate.h | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ExpandableTableView/Control/ExpandableTableView.m b/ExpandableTableView/Control/ExpandableTableView.m index b299ab1..9be709e 100644 --- a/ExpandableTableView/Control/ExpandableTableView.m +++ b/ExpandableTableView/Control/ExpandableTableView.m @@ -360,6 +360,16 @@ - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInte #pragma mark - #pragma mark UITableViewDelegateMethods +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { + if ([_expandedSectionIndexes containsIndex:indexPath.section] && indexPath.row != 0) { + return [_expandableDelegate tableView:self heightForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row - 1 inSection:indexPath.section]]; + } else if (indexPath.row == 0 && _ungroupSingleElement && [_expandableDataSource tableView:self numberOfRowsInSection:indexPath.section] == 1) { + return [_expandableDelegate tableView:self heightForRowAtIndexPath:indexPath]; + } else { + return [_expandableDelegate tableView:self heightForSection:indexPath.section]; + } +} + - (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath { //[_expandableDelegate tableView:<#(UITableView *)#> indentationLevelForRowAtIndexPath:<#(NSIndexPath *)#> if (indexPath.row != 0 && [_expandedSectionIndexes containsIndex:indexPath.section]) { diff --git a/ExpandableTableView/Control/ExpandableTableViewDelegate.h b/ExpandableTableView/Control/ExpandableTableViewDelegate.h index d90431a..4390e5b 100644 --- a/ExpandableTableView/Control/ExpandableTableViewDelegate.h +++ b/ExpandableTableView/Control/ExpandableTableViewDelegate.h @@ -19,8 +19,8 @@ - (BOOL)tableView:(ExpandableTableView *)tableView canRemoveSection:(NSUInteger)section; -//- (CGFloat)tableView:(ExpandableTableView *)tableView heightForSection:(NSUInteger)section; -//- (CGFloat)tableView:(ExpandableTableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; +- (CGFloat)tableView:(ExpandableTableView *)tableView heightForSection:(NSUInteger)section; +- (CGFloat)tableView:(ExpandableTableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; - (NSInteger)tableView:(ExpandableTableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath; - (void)tableView:(ExpandableTableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath; - (void)tableView:(ExpandableTableView *)tableView willDisplayCell:(UITableViewCell *)cell forSection:(NSUInteger)section; From 7eccd302a2edb42d950bed58de0657a0e16f1bd8 Mon Sep 17 00:00:00 2001 From: Jason Parekh Date: Thu, 28 Feb 2013 14:54:42 -0500 Subject: [PATCH 2/2] Safeguard if the height methods are not implemented by the delegate --- ExpandableTableView/Control/ExpandableTableView.m | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ExpandableTableView/Control/ExpandableTableView.m b/ExpandableTableView/Control/ExpandableTableView.m index 9be709e..d2dd095 100644 --- a/ExpandableTableView/Control/ExpandableTableView.m +++ b/ExpandableTableView/Control/ExpandableTableView.m @@ -362,12 +362,20 @@ - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInte - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if ([_expandedSectionIndexes containsIndex:indexPath.section] && indexPath.row != 0) { - return [_expandableDelegate tableView:self heightForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row - 1 inSection:indexPath.section]]; + if ([_expandableDelegate respondsToSelector:@selector(tableView:heightForRowAtIndexPath:)]) { + return [_expandableDelegate tableView:self heightForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row - 1 inSection:indexPath.section]]; + } } else if (indexPath.row == 0 && _ungroupSingleElement && [_expandableDataSource tableView:self numberOfRowsInSection:indexPath.section] == 1) { - return [_expandableDelegate tableView:self heightForRowAtIndexPath:indexPath]; + if ([_expandableDelegate respondsToSelector:@selector(tableView:heightForRowAtIndexPath:)]) { + return [_expandableDelegate tableView:self heightForRowAtIndexPath:indexPath]; + } } else { - return [_expandableDelegate tableView:self heightForSection:indexPath.section]; + if ([_expandableDelegate respondsToSelector:@selector(tableView:heightForSection:)]) { + return [_expandableDelegate tableView:self heightForSection:indexPath.section]; + } } + + return tableView.rowHeight; } - (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath {