ExpandableTableViewDataHelper is an utility API to help easily making an expandable tableview. Providing only three required parameters, one can have a static expandable tableview (by static, the tableview is not editable). Those three parameters include:
- the maximum number of level the tableview can expand.
- the data source array in each section
- the level array list in each section
All those datas are passed through the delegation methods (sort of like the UITableviewDelegate protocol).
This API does not include any UI components as I thought which can provide more flexibility. With a tableview to init it with, one can customize the UI in a freedom way.
You can do either pod or manual installation as you like.
For anyone who is more confortable with cocoapod, just copy the following line into your podfile.
pod ExpandableTableViewDataHelper '~> 0.1.0'
Then run pod install
as always.
For manual installation:
-
Clone this repo locally onto your computer, or press
Download ZIP
to download the latest master commit. -
Drag the ExpandableTableViewDataHelper folder into your project.
For anyone who want to add it as a static library:
- Clone this repo locally onto your computer, or press
Download ZIP
to download the latest master commit. - Select a simulator or an iOS Device as the scheme, and click run. You will have the lib in the Supporting Files folder. You then copy the .a lib from the Finder and copy to your project.
Provide a tableview with its designated method, while -init
should be no longer used.
- (instancetype)initWithTableView:(UITableView *)tableView;
For example, you have a UIViewController, which contains a UITableView as its view's subview, then you instantiate your data manager as follows:
ExpandableTableViewDataHelper *dataManager = [[ExpandableTableViewDataHelper alloc] initWithTableView:yourTableView];
Once you have a ExpandableTableViewDataHelper instance, you should set its delegate immediately:
dataManager.delegate = someDelegate;
Now you should fill in the delegation methods as it asks:
- (NSArray *)dataArrayInSection:(NSInteger)section;
- (NSInteger)numberOfLevels;
- (NSArray *)levelArraysInSection:(NSInteger)section;
When tableView:didSelectRowAtIndexPath:, you simply call this method to do the expanding.
- (void)didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- Meng Pan - Initial work - mpan753
This project is licensed under the MIT License - see the LICENSE.md file for details