iOS收藏

使用BlocksKit创建一个Tableview

2016-09-28  本文已影响0人  平壤的烟火
#import "Test.h"
#import <BlocksKit/A2DynamicDelegate.h>
@interface Test ()

@end

@implementation Test

- (void)viewDidLoad {
    [super viewDidLoad];
    UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
    [self.view addSubview:tableView];
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    A2DynamicDelegate *datasource = tableView.bk_dynamicDelegate;
    [datasource implementMethod:@selector(tableView:numberOfRowsInSection:) withBlock:^ NSInteger (UITableView *tableView,NSInteger section){
        return 3;
    }];
    [datasource implementMethod:@selector(tableView:cellForRowAtIndexPath:) withBlock:^ UITableViewCell * (UITableView *tableView, NSIndexPath *indexPath){
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        cell.textLabel.text = @"dfdfd";
        return cell;
    }];
    [datasource implementMethod:@selector(tableView:heightForRowAtIndexPath:) withBlock:^ CGFloat (UITableView *tableview , NSIndexPath * indexPath) {
        return 100;
    }];
    tableView.dataSource = datasource;
    tableView.delegate = datasource;
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
上一篇下一篇

猜你喜欢

热点阅读