Skip to content

Commit

Permalink
Copies changes from pull request 12: iSofTom#12
Browse files Browse the repository at this point in the history
  • Loading branch information
derpoliuk committed Jan 27, 2016
1 parent e752cf4 commit 4dec821
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#import "STCollapseTableView.h"

@interface ViewController () <UITableViewDataSource, UITableViewDelegate>
@interface ViewController () <UITableViewDataSource, UITableViewDelegate, STCollapseTableViewDelegate>

@property (weak, nonatomic) IBOutlet STCollapseTableView *tableView;

Expand Down Expand Up @@ -49,7 +49,7 @@ - (void)setupViewController
[UIColor greenColor],
[UIColor blueColor],
[UIColor purpleColor]];

self.data = [[NSMutableArray alloc] init];
for (int i = 0 ; i < [colors count] ; i++)
{
Expand All @@ -60,7 +60,7 @@ - (void)setupViewController
}
[self.data addObject:section];
}

self.headers = [[NSMutableArray alloc] init];
for (int i = 0 ; i < [colors count] ; i++)
{
Expand All @@ -73,53 +73,64 @@ - (void)setupViewController
- (void)viewDidLoad
{
[super viewDidLoad];


self.tableView.headerViewTapDelegate = self;
[self.tableView reloadData];
[self.tableView openSection:0 animated:NO];
}

- (IBAction)handleExclusiveButtonTap:(UIButton*)button
{
[self.tableView setExclusiveSections:!self.tableView.exclusiveSections];

[button setTitle:self.tableView.exclusiveSections?@"exclusive":@"!exclusive" forState:UIControlStateNormal];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.data count];
return [self.data count];
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* cellIdentifier = @"cell";
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell)
static NSString* cellIdentifier = @"cell";

UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
}
NSString* text = [[self.data objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
cell.textLabel.text = text;
return cell;
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
}

NSString* text = [[self.data objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
cell.textLabel.text = text;

return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[self.data objectAtIndex:section] count];
return [[self.data objectAtIndex:section] count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 40;
return 40;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
return [self.headers objectAtIndex:section];
}

@end
- (void)STCollapseTableView:(STCollapseTableView *)STCollapseTableView didSelectHeaderViewAtSection:(NSInteger)section
{
[[[UIAlertView alloc] initWithTitle:@""
message:[NSString stringWithFormat:@"headerView %ld tapped",section]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil]
show];
}

@end
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ so if you want the first section to be open after your view is loaded, you could
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView reloadData];
[self.tableView openSection:0 animated:NO];
}
Expand All @@ -43,6 +43,15 @@ This is automatically done for you in three conditions:
* The returned views haven't any UITapGestureRecognizer.
* the STCollapseTableView property `shouldHandleHeadersTap` is YES (which is the default value).

----
```
@property (nonatomic, weak) id<STCollapseTableViewDelegate> headerViewTapDelegate;
```
Just as the name, the herderViewTapDelegate is designed to handle hederViews tapping events, you can do things in the delegate method when a specified headerView tapped:

```
- (void)STCollapseTableView:(STCollapseTableView *)STCollapseTableView didSelectHeaderViewAtSection:(NSInteger)section;
```
## Installation

To include this component in your project, I recommend you to use [Cocoapods](http://cocoapods.org):
Expand Down
13 changes: 12 additions & 1 deletion STCollapseTableView/STCollapseTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
***********************************************************************************/

#import <UIKit/UIKit.h>
@class STCollapseTableView;

@protocol STCollapseTableViewDelegate <NSObject>

@optional

- (void)STCollapseTableView:(STCollapseTableView *)STCollapseTableView didSelectHeaderViewAtSection:(NSInteger)section;

@end

/**
* STCollapseTableView is a UITableView subclass that automatically collapse and/or expand your sections.
Expand Down Expand Up @@ -86,4 +95,6 @@
*/
- (BOOL)isOpenSection:(NSUInteger)sectionIndex;

@end
@property (nonatomic, weak) id<STCollapseTableViewDelegate> headerViewTapDelegate;

@end
Loading

0 comments on commit 4dec821

Please sign in to comment.