快速搭建UITableView
2018-09-10 本文已影响12人
羊妞麻麻
@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;
}