快速搭建UITableView

@property (nonatomic, strong) UITableView *mTableView;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.isNewNavigationBarStyle = YES;
    [self setNavItem];
    [self addSubViews];
    [self setConstraints];
    [self reloadData];
}

- (void)setNavItem{
    self.title = @"";
}

- (void)addSubViews{
    [self.view addSubview:self.mTableView];
}

- (void)setConstraints{
    [self.mTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).mas_equalTo(10);
        make.leading.trailing.mas_equalTo(self.view);
        if (@available(iOS 11.0, *)) {
            make.bottom.mas_equalTo(self.view.mas_safeAreaLayoutGuideBottom);
        } else {
            make.bottom.mas_equalTo(self.view.mas_bottom);
        }
    }];
}

懒加载

- (UITableView *)mTableView{
    if (!_mTableView) {
        _mTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _mTableView.delegate = self;
        _mTableView.dataSource = self;
        _mTableView.estimatedRowHeight = 112;
        _mTableView.rowHeight = UITableViewAutomaticDimension;
        if (@available(iOS 11.0, *)) {
            _mTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        } else {
            self.automaticallyAdjustsScrollViewInsets = NO;
        }
        [_mTableView registerClass:[SCEGProgressCell class] forCellReuseIdentifier:@"SCEGProgressCell"];
        _mTableView.backgroundColor = [UIColor SCBackGroundColor];
        _mTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        
    }
    return _mTableView;
}

代理实现

#pragma makr UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    SCEGProgressCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SCEGProgressCell"];
//    SCEGProgressModel *model = [self.interactor.listDataM objectAtIndex:indexPath.row];
    [cell setViewWithModel:nil];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//     SCEGProgressModel *model = [self.interactor.listDataM objectAtIndex:indexPath.row];
    SCEGImplementedDoneVC *vc = [[SCEGImplementedDoneVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 118;
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金 Cover 有什么料? 从这篇文章中你...
    hw1212阅读 14,527评论 2 59
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,647评论 25 709
  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 13,904评论 1 32
  • 一转眼 亢暑炎炎奈何天 一转念 未至秋风扇难圆 一转身 沧海曾经桑田变 一转闲 画壁飞龙云里眠 何处群山陌阡阡 何...
    飞镝阅读 1,310评论 0 0
  • 爸爸妈妈把我们养大,他们老了,真的老了,那个时刻为自己考虑的爸爸妈妈老了。难道我们不该为他们日益消瘦的身体做些努力...
    阳光kkkyyy阅读 3,669评论 0 0

友情链接更多精彩内容