MTBlockTableView
An iOS Table View that uses block-based delegation instead of protocols. Try it, we dare you.
Installation
- Preferred way is CocoaPods, just add
pod 'MTBlockTableView'
to your Podfile. - Copy
MTBlockTableView.h
andMTBlockTableView.m
into your project from theMTBlockTableView
target
Usage
MTBlockTableView
is an experimental, drop-in replacement for UITableView
which uses blocks for all protocol methods:
- (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;
}];
}
Discussion
The motivation for this library is a proof-of-concept that delegation through protocols could be replaced by delegation through blocks, and in many circumstances would be much move expressive and convenient for programmers. See this blog post for more thorough examples.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Write Tests
- Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request