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

Made UIExpandingTableViewCell an optional protocol #35

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions SLExpandableTableView/SLExpandableTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ typedef enum {

@protocol UIExpandingTableViewCell <NSObject>

@optional
@property (nonatomic, assign, getter = isLoading) BOOL loading;

@optional
@property (nonatomic, readonly) UIExpansionStyle expansionStyle;

@optional
- (void)setExpansionStyle:(UIExpansionStyle)style animated:(BOOL)animated;

@end
Expand Down
44 changes: 30 additions & 14 deletions SLExpandableTableView/SLExpandableTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,12 @@ - (void)expandSection:(NSInteger)section animated:(BOOL)animated {
[self beginUpdates];

UITableViewCell<UIExpandingTableViewCell> *cell = (UITableViewCell<UIExpandingTableViewCell> *)[self cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:section]];
cell.loading = NO;
[cell setExpansionStyle:UIExpansionStyleExpanded animated:YES];
if ([cell respondsToSelector:@selector(setLoading:)]) {
cell.loading = NO;
}
if ([cell respondsToSelector:@selector(setExpansionStyle:animated:)]) {
[cell setExpansionStyle:UIExpansionStyleExpanded animated:YES];
}

NSMutableArray *insertArray = [NSMutableArray array];
for (int i = 1; i < newRowCount; i++) {
Expand Down Expand Up @@ -284,9 +288,12 @@ - (void)collapseSection:(NSInteger)section animated:(BOOL)animated {
[self beginUpdates];

UITableViewCell<UIExpandingTableViewCell> *cell = (UITableViewCell<UIExpandingTableViewCell> *)[self cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:section]];
cell.loading = NO;
[cell setExpansionStyle:UIExpansionStyleCollapsed animated:YES];

if ([cell respondsToSelector:@selector(setLoading:)]) {
cell.loading = NO;
}
if ([cell respondsToSelector:@selector(setExpansionStyle:animated:)]) {
[cell setExpansionStyle:UIExpansionStyleCollapsed animated:YES];
}
NSMutableArray *deleteArray = [NSMutableArray array];
for (int i = 1; i < newRowCount; i++) {
[deleteArray addObject:[NSIndexPath indexPathForRow:i inSection:section] ];
Expand All @@ -301,9 +308,12 @@ - (void)collapseSection:(NSInteger)section animated:(BOOL)animated {

[self.animatingSectionsDictionary removeObjectForKey:@(section)];

[self scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:section]
atScrollPosition:UITableViewScrollPositionTop
animated:animated];
// By default the header cell is already on screen when it's collapsed.
// If a user wants to programatically collapse a section, they should handle scrolling themselves
// If you disagree feel free to uncomment this :)
// [self scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:section]
// atScrollPosition:UITableViewScrollPositionTop
// animated:animated];

void(^completionBlock)(void) = ^{
if ([self respondsToSelector:@selector(scrollViewDidScroll:)]) {
Expand Down Expand Up @@ -437,13 +447,19 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
if (indexPath.row == 0) {
UITableViewCell<UIExpandingTableViewCell> *cell = [self.myDataSource tableView:self expandingCellForSection:indexPath.section];
if ([self.downloadingSectionsDictionary[key] boolValue]) {
[cell setLoading:YES];
if ([cell respondsToSelector:@selector(setLoading:)]) {
[cell setLoading:YES];
}
} else {
[cell setLoading:NO];
if ([self.showingSectionsDictionary[key] boolValue]) {
[cell setExpansionStyle:UIExpansionStyleExpanded animated:NO];
} else {
[cell setExpansionStyle:UIExpansionStyleCollapsed animated:NO];
if ([cell respondsToSelector:@selector(setLoading:)]) {
[cell setLoading:NO];
}
if ([cell respondsToSelector:@selector(setExpansionStyle:animated:)]) {
if ([self.showingSectionsDictionary[key] boolValue]) {
[cell setExpansionStyle:UIExpansionStyleExpanded animated:NO];
} else {
[cell setExpansionStyle:UIExpansionStyleCollapsed animated:NO];
}
}
}
return cell;
Expand Down