Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional expand or collapse #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions SLExpandableTableView/SLExpandableTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ typedef enum {
@optional
- (void)tableView:(SLExpandableTableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPathWhileAnimatingSection:(NSIndexPath *)indexPath;

- (BOOL)tableView:(SLExpandableTableView *)tableView shouldExpandSection:(NSUInteger)section animated:(BOOL)animated;
- (void)tableView:(SLExpandableTableView *)tableView willExpandSection:(NSUInteger)section animated:(BOOL)animated;
- (void)tableView:(SLExpandableTableView *)tableView didExpandSection:(NSUInteger)section animated:(BOOL)animated;

- (BOOL)tableView:(SLExpandableTableView *)tableView shouldCollapseSection:(NSUInteger)section animated:(BOOL)animated;
- (void)tableView:(SLExpandableTableView *)tableView willCollapseSection:(NSUInteger)section animated:(BOOL)animated;
- (void)tableView:(SLExpandableTableView *)tableView didCollapseSection:(NSUInteger)section animated:(BOOL)animated;

Expand Down
33 changes: 30 additions & 3 deletions SLExpandableTableView/SLExpandableTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,39 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
// expand cell got clicked
if ([self.myDataSource tableView:self needsToDownloadDataForExpandableSection:indexPath.section]) {
// we need to download some data first
[self downloadDataInSection:indexPath.section];
if ([self.myDelegate respondsToSelector:@selector(tableView:shouldExpandSection:animated:)]) {
BOOL shouldExpand = [self.myDelegate tableView:self shouldExpandSection:indexPath.section animated:YES];
if (shouldExpand) {
[self downloadDataInSection:indexPath.section];
} else {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
} else {
[self downloadDataInSection:indexPath.section];
}
} else {
if ([self.showingSectionsDictionary[key] boolValue]) {
[self collapseSection:indexPath.section animated:YES];
if ([self.myDelegate respondsToSelector:@selector(tableView:shouldCollapseSection:animated:)]) {
BOOL shouldCollapse = [self.myDelegate tableView:self shouldCollapseSection:indexPath.section animated:YES];
if (shouldCollapse) {
[self collapseSection:indexPath.section animated:YES];
} else {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
} else {
[self collapseSection:indexPath.section animated:YES];
}
} else {
[self expandSection:indexPath.section animated:YES];
if ([self.myDelegate respondsToSelector:@selector(tableView:shouldExpandSection:animated:)]) {
BOOL shouldExpand = [self.myDelegate tableView:self shouldExpandSection:indexPath.section animated:YES];
if (shouldExpand) {
[self expandSection:indexPath.section animated:YES];
} else{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
} else {
[self expandSection:indexPath.section animated:YES];
}
}
}
} else {
Expand Down