TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Nov 2015 |
Maintained by Darrarski.
Object-oriented UITableViewDataSource and UITableViewDelegate protocols proxy
Simple wrapper around UITableViewDataSource
and UITableViewDelegate
protocols that allows easy UITableView
content configuration using blocks or custom objects representing sections and rows.
General logic behind DRTableViewManager
:
DRTableViewManager
- implements UITableViewDataSource
and UITableViewDelegate
protocols, owns DRTableViewSectionController
DRTableViewSectionController
- defines sections (DRTableViewSection
) for given table viewDRTableViewSection
- represents table view section; defines rows (DRTableViewRow
) for that section; implements sections-connected part of UITableViewDataSource
and UITableViewDelegate
protocolsDRTableViewRow
- represents table view row; defines cell (UITableViewCell
) for that row; implements rows-connected part of UITableViewDataSource
and UITableViewDelegate
protocolsFull UITableViewDataSource
and UITableViewDelegate
protocols are supported. For example, DRTableViewSection
also defines section's header and footer (as well as their heights), and DRTableViewRow
defines UITableViewCell
height, didSelect action etc.
In addition, DRTableViewManager
was designed to allow using UITableViewAutomaticDimension
cell height on iOS 7. Behaviour for resolving automatic cell height can be configured by setting automaticRowHeightResolvingType
property on DRTableViewManager
object. DRTableViewAutomaticRowHeightResolvingType
has three available options:
DRTableViewResolveAutomaticRowHeightAutomatically
- row height will be computed by iOS automatically using UITableViewAutomaticDimension
(available only on iOS 8).DRTableViewResolveAutomaticRowHeightManually
- row height will be computed by resolving AutoLayout on cell. It will be handled automatically by DRTableViewManager
if tableViewCellForComputingRowHeightAtIndexPathBlock
is set for row.DRTableViewResolveAutomaticRowHeightAutomaticallyIfAvailable
(default value) - UITableViewAutomaticDimension
will be used if availabe, otherwise height will be resolved like when using DRTableViewResolveAutomaticRowHeightManually
option.If you are using UIKit elements that requires setting preferredMaxLayoutWidth
to layout properly, use DRTableViewResolveAutomaticRowHeightManually
option to avoid issues on different iOS versions. See Example 2 for more details.
You can integrate DRTableViewManager
with your project using Cocoapods. To do so, you will need to add one of the following lines to your Podfile:
For stable release (recommended):
pod 'DRTableViewManager', '~> 1.0.13'
Which creates dependecy for version >= 1.0.13
and < 1.1
You can also download zip archive of given release from releases page.
Check out included example project or TableViewDemo
in its own reposotory.
Shows basic usage, where sections and cells are statically defined in arrays.
Shows basic usage as well, but configures automatic cell heights basing on their content. Works for both iOS 8 (using native UITableViewAutomaticDimension
) and iOS 7 (computes height with AutoLayout - see source code for details).
Example usage:
DRTableViewGenericSectionsController *sectionsController = [[DRTableViewGenericSectionsController alloc] init];
sectionsController.sectionsCountBlock = ^NSInteger {
return 3;
};
sectionsController.sectionAtIndexBlock = ^NSObject <DRTableViewSection> *(NSInteger sectionIndex) {
return [DRTableViewGenericSection createWithBlock:^(DRTableViewGenericSection *section) {
section.tableViewTitleForHeaderInSectionBlock = ^NSString *(UITableView *tableView, NSInteger tableSectionIndex) {
return [NSString stringWithFormat:@"Section %ld", (long)tableSectionIndex];
};
section.tableViewHeightForHeaderInSectionBlock = ^CGFloat(UITableView *tableView, NSInteger tableSectionIndex) {
return 30;
};
section.tableViewNumberOfRowsInSectionBlock = ^NSInteger(UITableView *tableView, NSInteger tableSectionIndex) {
return 3;
};
section.rowAtIndexBlock = ^NSObject <DRTableViewRow> *(NSInteger rowIndex) {
return [DRTableViewGenericRow createWithBlock:^(DRTableViewGenericRow *row) {
row.tableViewHeightForRowAtIndexPathBlock = ^CGFloat(UITableView *tableView, NSIndexPath *indexPath) {
return 44;
};
row.tableViewCellForRowAtIndexPathBlock = ^UITableViewCell *(UITableView *tableView, NSIndexPath *indexPath) {
UITableViewCell *cell = [[UITableViewCell alloc] init];
cell.textLabel.text = [NSString stringWithFormat:@"Row %ld", (long)indexPath.row];
return cell;
};
}];
};
}];
};
_tableViewManager = [[DRTableViewManager alloc] initWithSectionsController:sectionsController];
[_tableViewManager registerInTableView:self.tableView];
Fixed issue with manually computed row height on iOS 9
Added
scrollViewDelegate
(<UIScrollViewDelegate>
) property toDRTableViewManager
Added helper methods to
DRTableViewManager
:
rowForCell:atIndexPath:
sectionForFooterHeaderView:atIndex:
Fixed import statements in header files
DRTableViewManager
updated, addedsectionAtIndex:
androwAtIndexPath:
methods
DRTableViewGenericRow
andDRTableViewGenericSection
initialization adjusted to common patters, builder method renamed fromcreateWithBlock:
tonewWithBlock:
Added cells cache to
DRTableViewManager
, useful for caching cells used for computing row heightExamples updated
Added
automaticRowHeightResolvingType
property toDRTableViewManager
Examples updated
Added
tableView:cellForComputingRowHeightAtIndexPath:
method toDRTableViewRow
protocol for supportingUITableViewAutomaticDimension
cell height under iOS 7Added
tableView:configureCell:forRowAtIndexPath:
method toDRTableViewRow
protocolExamples updated
Deployment target changed to iOS 7.0,
DRTableViewManager
is compatible with both iOS 7 and iOS 8.Added Example 2 that shows how to implement automatic cell heights that works natively on iOS 8, but also on iOS 7 with some additional code.
Fixed - wrong method called on
DRTableViewRow
object fortableView:heightForRowAtIndexPath:
method fromUITableViewDelegate
protocol
Fixed invalid protocol compliance definitions for arrays
Minor fixes
Inital release, supports iOS 8
The MIT License (MIT) - check out included LICENSE file