美文网首页iOS收藏
使用BlocksKit创建一个Tableview

使用BlocksKit创建一个Tableview

作者: 平壤的烟火 | 来源:发表于2016-09-28 12:22 被阅读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
    

    相关文章

      网友评论

        本文标题:使用BlocksKit创建一个Tableview

        本文链接:https://www.haomeiwen.com/subject/ztihyttx.html