HoloTableView
HoloTableView provides chained syntax calls that encapsulate delegate methods for UITableView. The delegate methods for UITableView are distributed to each cell, each cell having its own method for setting Class, model, height, and click event, etc.
Features
- Provide section and row maker to handle proxy events of
UITableVIew. - Provide protocols, implemented in cells, headers and footers to handle proxy events of
UITableVIew. - Provide left-slide and right-slide actions for
cell. - Passing events through the responder chain.
- Support to regist maps (key-Class) for row, header and footer.
- HoloTableViewMGPlugin to support
MGSwipeTableCell, add swip actions forcell. - Diff reload data. HoloTableViewDiffPlugin to support
DeepDiff - Modern Objective-C and better Swift support.
Example
To run the example project, clone the repo, and run pod install from the Example directory first.
Integration with 3rd party libraries
- HoloTableViewMGPlugin - plugin to support MGSwipeTableCell, add swip actions for
cell.MGSwipeTableCellis an easy to useUITableViewCellsubclass that allows to display swipeable buttons with a variety of transitions. - HoloTableViewDiffPlugin - plugin to support DeepDiff, diff reload a section of
UITableView.DeepDifftells the difference between 2 collections and the changes as edit steps.
Usage
1. Make a simple cell list
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
[self.view addSubview:tableView];
[tableView holo_makeRows:^(HoloTableViewRowMaker * _Nonnull make) {
// make a cell
make.row(ExampleTableViewCell.class).model(NSDictionary.new).height(44);
// make a list
for (NSObject *obj in NSArray.new) {
make.row(ExampleTableViewCell.class).model(obj).didSelectHandler(^(id _Nullable model) {
NSLog(@"did select row : %@", model);
});
}
}];
[tableView reloadData];
// etc.The holo_makeRows: method is used to create a list of rows. Each row is a cell. More properties provided for row see: HoloTableViewRowMaker.h and HoloTableRowMaker.h
Requirements for cell
Conforms to protocol HoloTableViewCellProtocol, HoloTableView will automatically identify cell whether implement these methods and calls, the commonly used two methods:
@required
// set the model to cell
// the model is the object passed in by make.model()
- (void)holo_configureCellWithModel:(id)model;
@optional
// return cell height( Priority is higher than: 'heightHandler' and 'height' of maker)
// the model is the object passed in by make.model()
+ (CGFloat)holo_heightForCellWithModel:(id)model;See HoloTableViewCellProtocol more methods: HoloTableViewCellProtocol
You can also call your own methods by configuring properties such as configSEL, heightSEL, etc. More properties can find in HoloTableRowMaker.h.
Note that attributes such as height, estimatedHeight, etc. that exist SEL have priority:
- First judge whether
cellimplementsheightSELmethod - Secondly, verify the implementation of the
heightHandlerblock - Finally, determine whether the property
heightis assigned
2. Make a section list (contain header, footer, row)
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
[self.view addSubview:tableView];
[tableView holo_makeSections:^(HoloTableViewSectionMaker * _Nonnull make) {
make.section(TAG)
.header(ExampleHeaderView.class)
.headerModel(NSDictionary.new)
.footer(ExampleFooterView.class)
.footerModel(NSDictionary.new)
.makeRows(^(HoloTableViewRowMaker * _Nonnull make) {
// make a cell
make.row(ExampleTableViewCell.class).model(NSDictionary.new).height(44);
// make a list
for (NSObject *obj in NSArray.new) {
make.row(ExampleTableViewCell.class).model(obj).didSelectHandler(^(id _Nullable model) {
NSLog(@"did select row : %@", model);
});
}
});
}];
[tableView reloadData];The holo_makeSections: method is used to create a list of section. More properties provided for section see: HoloTableViewSectionMaker.h and HoloTableSectionMaker.h
Requirements for header and footer
- header: conforms to protocol
HoloTableViewHeaderProtocol, implement these methods, the commonly used two methods:
@required
// set the model to header
// the model is the object passed in by make.headerModel()
- (void)holo_configureHeaderWithModel:(id)model;
@optional
// return header height( Priority is higher than: 'headerHeightHandler' and 'headerHeight' of maker)
// the model is the object passed in by make.headerModel()
+ (CGFloat)holo_heightForHeaderWithModel:(id)model;- Footer: conforms to protocol
HoloTableViewFooterProtocol, implement these methods, the commonly used two methods:
@required
// set the model to footer
// the model is the object passed in by make.footerModel()
- (void)holo_configureFooterWithModel:(id)model;
@optional
// return footer height( Priority is higher than: 'footerHeightHandler' and 'footerHeight' of maker)
// the model is the object passed in by make.footerModel()
+ (CGFloat)holo_heightForFooterWithModel:(id)model;See HoloTableViewHeaderProtocol and HoloTableViewFooterProtocol more methods: HoloTableViewHeaderProtocol and HoloTableViewFooterProtocol
You can also call your own methods by configuring properties such as headerConfigSEL, footerConfigSEL, etc. More properties can find in HoloTableSectionMaker.h.
Like cell, properties that contain SEL also have a priority.
3. Methods for section
// adding
[self.tableView holo_makeSections:^(HoloTableViewSectionMaker * _Nonnull make) {
make.section(TAG);
}];
// inserting at index
[self.tableView holo_insertSectionsAtIndex:0 block:^(HoloTableViewSectionMaker * _Nonnull make) {
make.section(TAG);
}];
// updating with tag value by maker
[self.tableView holo_updateSections:^(HoloTableViewSectionMaker * _Nonnull make) {
make.section(TAG);
}];
// resetting with tag value by maker
[self.tableView holo_remakeSections:^(HoloTableViewSectionMaker * _Nonnull make) {
make.section(TAG);
}];
// deleting
[self.tableView holo_removeAllSections];
// deleting with tag value
[self.tableView holo_removeSections:@[TAG]];
// reloadData
[self.tableView reloadData];UITableView+HoloTableView.h provides a series of methods for manipulating sections, including adding, inserting, updating, resetting, deleting, etc.
More methods provided for section see: UITableView+HoloTableView.h (about section)
4. Methods for row
// adding
[self.tableView holo_makeRows:^(HoloTableViewRowMaker * _Nonnull make) {
make.row(ExampleTableViewCell.class);
}];
// adding to section with tag value
[self.tableView holo_makeRowsInSection:TAG block:^(HoloTableViewRowMaker * _Nonnull make) {
make.row(ExampleTableViewCell.class);
}];
// inserting at index
[self.tableView holo_insertRowsAtIndex:0 block:^(HoloTableViewRowMaker * _Nonnull make) {
make.row(ExampleTableViewCell.class);
}];
// inserting at index to section with tag value
[self.tableView holo_insertRowsAtIndex:0 inSection:TAG block:^(HoloTableViewRowMaker * _Nonnull make) {
make.row(ExampleTableViewCell.class);
}];
// updating
[self.tableView holo_updateRows:^(HoloTableViewUpdateRowMaker * _Nonnull make) {
make.tag(TAG).height(120);
}];
// resetting
[self.tableView holo_remakeRows:^(HoloTableViewUpdateRowMaker * _Nonnull make) {
make.tag(TAG).model(NSDictionary.new).height(120);
}];
// deleting
[self.tableView holo_removeAllRowsInSections:@[TAG]];
// deleting
[self.tableView holo_removeRows:@[TAG]];
// reloadData
[self.tableView reloadData];UITableView+HoloTableView.h provides a series of methods for manipulating rows, including adding, inserting, updating, resetting, deleting, etc.
More methods provided for row see: UITableView+HoloTableView.h (about row)
5. Retrieve Delegate
You can retrieve the delegate of UITableView at any time, such as:
// first way
self.tableView.holo_proxy.dataSource = self;
self.tableView.holo_proxy.delegate = self;
self.tableView.holo_proxy.scrollDelegate = self;
// second way
[self.tableView holo_makeTableView:^(HoloTableViewMaker * _Nonnull make) {
make.dataSource(self).delegate(self).scrollDelegate(self);
}];Once you set up dataSource, delegate, scrollDelegate and implement some of their methods, HoloTableView will use your methods and return values first. For specific logic, please refer to: HoloTableViewProxy.m
6. Regist key-Class map
HoloTableView supports key value mappings for headers, footers, and rows in advance. For example:
// regist key-Class map
[self.tableView holo_makeTableView:^(HoloTableViewMaker * _Nonnull make) {
make
.makeHeadersMap(^(HoloTableViewHeaderMapMaker * _Nonnull make) {
make.header(@"header1").map(ExampleHeaderView1.class);
make.header(@"header2").map(ExampleHeaderView2.class);
// ...
})
.makeFootersMap(^(HoloTableViewFooterMapMaker * _Nonnull make) {
make.footer(@"footer1").map(ExampleFooterView1.class);
make.footer(@"footer2").map(ExampleFooterView2.class);
// ...
})
.makeRowsMap(^(HoloTableViewRowMapMaker * _Nonnull make) {
make.row(@"cell1").map(ExampleTableViewCell1.class);
make.row(@"cell2").map(ExampleTableViewCell2.class);
// ...
});
}];
// use the key value
[self.tableView holo_makeSections:^(HoloTableViewSectionMaker * _Nonnull make) {
// section 1
make.section(TAG1)
.headerS(@"header1")
.footerS(@"footer1")
.makeRows(^(HoloTableViewRowMaker * _Nonnull make) {
make.rowS(@"cell1");
make.rowS(@"cell2");
});
// section 2
make.section(TAG2)
.headerS(@"header2")
.footerS(@"footer2")
.makeRows(^(HoloTableViewRowMaker * _Nonnull make) {
make.rowS(@"cell1");
make.rowS(@"cell2");
});
// ...
}];If you have registered key-class mapping in advance, headerS, footerS and rowS are used to fetch Class according to the registered mapping
If you are not registered, headerS, footerS, rowS directly convert the string passed in to Class using the NSClassFromString(NSString * _Nonnull aClassName) method.
Installation
HoloTableView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'HoloTableView'Author
gonghonglou, [email protected]
License
HoloTableView is available under the MIT license. See the LICENSE file for more info.