// // FirstViewController.m // PersonalCenter // // Created by Arch on 2017/6/16. // Copyright © 2017年 mint_bin. All rights reserved. // #import "FirstViewController.h" #import "HomeSchoolContentCell.h" @interface FirstViewController () @property (nonatomic, strong) UILabel * titleL; @property (nonatomic, copy) NSString * content; @property(nonatomic, strong) UITableView *tableView; @end @implementation FirstViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = UIColorHex(0xF8F9FB); [self creatTableView]; } - (void)creatTableView { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH, SCREEN_HEIGHT - NAVH - 150) style:UITableViewStyleGrouped]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.showsVerticalScrollIndicator = NO; _tableView.showsHorizontalScrollIndicator = NO; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView.backgroundColor = [UIColor whiteColor]; _tableView.rowHeight = 50; [self.view addSubview:_tableView]; } - (void)setDataText:(NSString *)text { self.content = text; [self.tableView reloadData]; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 45.f; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.01f; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 45)]; [view addSubview:self.titleL]; [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_offset(15); make.centerY.right.mas_equalTo(view); }]; return view; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return [UIView new]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewAutomaticDimension; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { HomeSchoolContentCell * cell = [HomeSchoolContentCell configCell:tableView indexPath:indexPath]; [cell setDataText:self.content]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; } - (UILabel *)titleL { if (!_titleL) { _titleL = [UILabel new]; _titleL.font = [UIFont systemFontOfSize:16]; _titleL.textColor = UIColorHex(0x222222); _titleL.text = @"学校简介"; } return _titleL; } @end