PDTiledView 0.1.0

PDTiledView 0.1.0

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布最新发布2014年12月

Parker Wightman 维护。



  • 作者:
  • Parker

手风琴样式表格视图,基于块的服务委托。

安装

CocoaPods 马上就会,但现在您可以先将 PDTiledView.h/.m 添加到您的项目中。

使用方法

UITableView 非常相似,但是使用 sectionstiles 而不是 sectionsrows。它还使用块来代替协议进行委托。

示例

PDTiledView *tiledView = ...;

tiledView.numberOfSectionsBlock = ^NSInteger { return 4; };

tiledViewdView.numberOfTilesInSectionBlock = ^NSInteger (NSInteger section) { return 20; };

所有 sectionstiles 都是 UIControl 的子类,例如 UIButton 或您自己制作的自定义控件。(这可能很快会切换到 UIView,尚未确定)。

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;
};

基于块的服务委托的结果,您应该在视图首次显示时显式调用 reloadData

[tiledView reloadData];

您也可以通过调用 selectSection:animated: 来程序化选择一个章节。

[tiledView selectSection:0 animated:NO];

还有一些可选的块可以进一步自定义您喜欢的样式。它们与 UITableViewDelegate/DataSource 的对应物相匹配

  • heightForSectionControlBlock
  • heightForTilesInSectionBlock
  • didSelectSectionBlock
  • didSelectTileAtIndexPathBlock
  • willDisplaySectionBlock
  • willDisplayTileAtIndexPathBlock

讨论

内部实现不使用 UITableView,因此虽然一些内容被缓存,但 tile 不是像在 UITableView 中的行那样动态加载和缓存的。如果不显示数千个 tile 或者 tile 是极其渲染密集的,这不会有什么大问题。欢迎提交拉取请求以帮助实现缓存,或者可能使用内部的 UITableView

这也意味着 controlForSectionBlockcontrolForTileAtIndexPathBlock 不会多次调用,通常只会调用一次。

贡献

  1. 分支它
  2. 创建您的功能分支(`git checkout -b my-new-feature`
  3. 提交您的更改(`git commit -am '添加一些功能'`
  4. 将更改推送到分支(`git push origin my-new-feature`
  5. 创建新的拉取请求

贡献者

Parker Wightman@parkerwightman