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.
- 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.
- HoloTableViewMGPlugin to support
MGSwipeTableCell
, add swip actions forcell
. - Diff reload data. HoloTableViewDiffPlugin to support
DeepDiff
- Support to reload a table view by setting datasource with
HoloTableSection
andHoloTableRow
. - Modern Objective-C and better Swift support.
To run the example project, clone the repo, and run pod install
from the Example directory first.
- HoloTableViewMGPlugin - plugin to support MGSwipeTableCell, add swip actions for
cell
.MGSwipeTableCell
is an easy to useUITableViewCell
subclass that allows to display swipeable buttons with a variety of transitions. - HoloTableViewDiffPlugin - plugin to support DeepDiff, diff reload a section of
UITableView
.DeepDiff
tells the difference between 2 collections and the changes as edit steps.
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 with a default section. Each row
is a cell
. More properties provided for row see: HoloTableViewRowMaker.h and HoloTableRowMaker.h
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
cell
implementsheightSEL
method - Secondly, verify the implementation of the
heightHandler
block - Finally, determine whether the property
height
is assigned
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
- 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.
// 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)
// 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)
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
Make a section list with HoloTableSection
and HoloTableRow
:
HoloTableSection *section = [HoloTableSection new];
section.tag = TAG;
section.header = ExampleHeaderView.class;
section.headerModel = @{@"title":@"header"};
section.footer = ExampleFooterView.class;
section.footerModel = @{@"title":@"footer"};
section.footerHeight = 100;
NSMutableArray *rows = [NSMutableArray new];
for (NSDictionary *dict in self.modelArray) {
HoloTableRow *row = [HoloTableRow new];
row.cell = ExampleTableViewCell.class;
row.model = dict;
[rows addObject:row];
}
section.rows = rows;
self.tableView.holo_sections = @[section];
[self.tableView reloadData];
HoloTableView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'HoloTableView'
gonghonglou, gonghonglou@icloud.com
HoloTableView is available under the MIT license. See the LICENSE file for more info.