MAYCollectionViewDataSource 0.0.5

MAYCollectionViewDataSource 0.0.5

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2018 年 4 月

minerany 维护。



  • minerany

MAYCollectionViewDataSource

安装

pod 'MAYCollectionViewDataSource', :git => 'https://github.com/minerany/MAYCollectionViewDataSource.git'

使用方法

例如创建 UITableView dataSource

导入头文件

#import "MAYCollectionViewDataSource+UITableView.h"

创建一个 MAYCollectionViewDataSource 实例并配置它

MAYCollectionViewDataSource *dataSource = [MAYCollectionViewDataSource new];
MAYCollectionViewCellSource *cellSource = [MAYCollectionViewCellSource sourceWithIdentifier:@"cell"];
cellSource.data = @" hello miner";
[cellSource setTarget:self configSelector:@selector(__configCustomCell:cellSource:)];
[cellSource setTarget:self actionSelector:@selector(__performAction:cellSource:)];
[dataSource addCellSource:@[cellSource]];

使用 MAYDeclareConfigCellSelectorMAYDeclareCellActionSelector 在接口扩展中声明 configSelector 和 actionSelector

MAYDeclareConfigCellSelector(__configCustomCell, UITableViewCell *, MAYCollectionViewCellSource*)
MAYDeclareCellActionSelector(__performAction, UITableViewCell *, MAYCollectionViewCellSource*)

然后实现 config 和 action 方法

- (void)__configCustomCell:(UITableViewCell *)cell cellSource:(MAYCollectionViewCellSource *)cellSource {
  cell.textLabel.text = cellSource.data;
}

- (void)__performAction:(UITableViewCell *)cell cellSource:(MAYCollectionViewCellSource *)cellSource {
  NSLog(@"%@",cellSource.data);
}

然后完成 UttableView dataSource 的配置!

如果你想要实现 UttableView scrollviewDidScroll 代理方法,你可以设置为

dataSource.interceptedTableViewDelegate = self;

在这个代理中,你可以实现你想要的 UttableViewDelegate 代理方法。

MAYCollectionViewDataSource 还支持自适应大小的 UttableViewCell,如果你设置

tableView.rowHeight = UITableViewCellAutomaticHeight;

更多详细信息可以在 ExampleViewController…