MTBlockTableView 0.0.1

MTBlockTableView 0.0.1

测试已测试
语言语言 Obj-CObjective C
许可协议 BSD
发布日期最后发布2014年12月

Adam Kirk 维护。



  • 编译者
  • Parker Wightman

一个使用基于块的代理代替协议的 iOS 表视图。试试吧,我们敢

安装

  1. 首选方式是 CocoaPods,只需将 `pod 'MTBlockTableView'` 添加到您的 Podfile。
  2. 将 `MTBlockTableView.h` 和 `MTBlockTableView.m` 拷贝到您的项目中的 `MTBlockTableView` 目标中

使用

MTBlockTableView 是一个实验性的 `UITableView` 的替换,它使用块来执行所有协议方法

- (void)viewDidLoad
{
    [super viewDidLoad];

    [_tableView setNumberOfRowsInSectionBlock:^NSInteger(UITableView *tableView, NSInteger section) {
        return 10;
    }];

    [_tableView setCellForRowAtIndexPathBlock:^UITableViewCell *(UITableView *tableView, NSIndexPath *indexPath) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

        cell.textLabel.text = [@(indexPath.row) stringValue];

        return cell;
    }];
}

讨论

该库的动力是证明概念,即通过协议的代理可以通过基于块的代理来实现,在许多情况下将更加表达和方便。请参见 此博客文章 了解更多详细示例。