Accordion-style table view, with block-based delegation.
CocoaPods by putting pod 'PDTiledView' in your Podfile, or you can drop PDTiledView{.h,.m}
into your project. Uses ARC and requires iOS 5.1 or higher.
Very similar to UITableView, but uses sections and tiles instead of sections and rows. It also
uses blocks instead of protocols for delegation.
PDTiledView *tiledView = ...;
tiledView.numberOfSectionsBlock = ^NSInteger { return 4; };
tiledViewdView.numberOfTilesInSectionBlock = ^NSInteger (NSInteger section) { return 20; };All sections and tiles are just UIControl subclasses, such as UIButton or a custom control of
your making. (This may switch to UIView later, not sold on it yet).
tiledView.controlForSectionBlock = ^UIControl *(NSInteger section) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor = [UIColor whiteColor];
return button;
};
tiledView.controlForTileAtIndexPathBlock = ^UIControl *(PDIndexPath indexPath) {
UIButton *button = [UIButton buttonWithType:UIControlIButtonTypeCustom];
return button;
};As a result of block-based delegation, you should explicitly call reloadData the first time the view will be displayed.
[tiledView reloadData];You can also programmatically select a section by calling selectSection:animated:.
[tiledView selectSection:0 animated:NO];There are also optional blocks to further customize how you like. They match up with their UITableViewDelegate/DataSource counterparts:
heightForSectionControlBlockheightForTilesInSectionBlockdidSelectSectionBlockdidSelectTileAtIndexPathBlockwillDisplaySectionBlockwillDisplayTileAtIndexPathBlock(This is where you should apply styling that isframe-dependent, as its final dimensions will be set. Same withwillDisplaySectionBlock)
The internal implementation does not use UITableViews, so while some things are cached, tiles are not loaded
on-the-fly and cached as rows are in UITableView. This shouldn't be a big deal unless you are displaying 1,000s
of tiles or tiles are extremely rendering intensive. Pull requests are more than welcome to help implement caching,
or perhaps to use UITableViews internally.
This also means that controlForSectionBlock and controlForTileAtIndexPathBlock are not called multiple times,
usually just once per call to reloadData. The UIScrollViews containing the tiles for the selected section are
loaded lazily the first time and cached thereafter until the next call to reloadData.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Added some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
