GHUITableViewHelper 1.1

GHUITableViewHelper 1.1

测试测试
Lang语言 Obj-CObjective C
许可证 自定义
发布上次发布2017年5月

tangshimi 维护。



  • 作者:
  • tangshimi

## 简介 封装了常用几个 UITableViewDelegate 与 UITableViewDataSource 方法,使用起来更方便。

## 使用方法 1.基本使用

UITableView *tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
[view addSubview:tableView];

tableView.gh_delegate = self;
tableView.gh_registerCells = @{ @"Model" : [tableViewCell class] };

Model *modle1 = [[myModel alloc] init];
Model *modle2 = [[myModel alloc] init];
tableView.gh_dataArray = @[@[modle1, modle2 ], @[modle1, modle2]];

[tableView reloadData];
注:Model是数据模型的类名,tableViewCell必须是遵守GHTableViewCellDelegate协议的UITableViewCell的子类;tableView.dataArray 是一个二维数组

2. TABLE VIEW CELL 点击的回调提供代理和 block 两种方式

2.1 block:
tableView.gh_cellDidSelectBlock = ^(id model, NSIndexPath *indexPath) {

};
2.2 delegate:
- (void)tableView:(UITableView *)tableView model:(id)model didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

}

3. TABLE VIEW CELL 内部的事件的回调提供代理和 block 两种方式

3.1 delgegate
- (void)tableView:(UITableView *)tableView model:(id)model cellEventType:(NSUInteger)type cellIndexPath:(NSIndexPath *)indexPath
{

}
3.2 block
tableView.gh_cellDetailEventBlock = ^(id model, NSUInteger type, NSIndexPath *indexPath){

};
注:UITableViewCell中对应的事件要使用cell的delegate调用GHTableViewCellEventDelegate协议中
    - (void)model:(id)model cellEventType:(NSUInteger)type cellIndexPath:(NSIndexPath *)indexPath;
    方法,如下传出cell的一个button点击事件
- (void)buttonAction:(UIButton *)button
{
    if ([self.delegate respondsToSelector:@selector(model:cellEventType:cellIndexPath:)]) {
        [self.delegate model:model cellEventType:1 cellIndexPath:self.currentIndexPath];
    }
}

4. 能在包含 GHTableViewDataSoureImp 和 GHTableViewDelegateImp 中其他UITableViewController 的方法中使用其他 UITableViewDelegate 和 UITableViewDataSource 方法。例如:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}

## CocoaPods

pod 'GHUITableViewHelper'