快速表格

Controller里面

.m文件

@interface CommentListC () <UITableViewDelegate,UITableViewDataSource>
@property (nonatomic ,weak) UITableView *tableView;
@property (nonatomic ,strong) NSArray *dataArr;
@end

@implementation CommentListC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"";
    
    [self setupTab];
}

- (void)setupTab{
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, K_SCREEN_WIDTH, K_SCREEN_HEIGHT - 64) style:UITableViewStyleGrouped];
    [self.view addSubview:tableView];
    self.tableView = tableView;
    tableView.showsVerticalScrollIndicator = NO;
    tableView.delegate = self;
    tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    [self.tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];
    
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TeacherCell *cell = [TeacherCell cellWithTableView:tableView];
    cell.model = self.dataArr[indexPath.section];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 90;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.02;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 45;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *footer = [UIView new];
    footer.size = CGSizeMake(ZBscreenW, 45);
    
    UIButton *btn = [UIButton new];
    btn.layer.borderColor = [UIColor colorFromHexString:@"e1e1e1"].CGColor;
    btn.layer.borderWidth = 0.5;
    [btn.titleLabel setFont:[UIFont systemFontOfSize:14]];
    btn.frame = CGRectMake(0, 0, ZBscreenW, 45);
    [btn setTitle:@"查看更多 >" forState:UIControlStateNormal];
    [btn setTitleColor:LGThemeColor forState:UIControlStateNormal];
//    [btn addTarget:self action:@selector(showMore:) forControlEvents:UIControlEventTouchUpInside];
    [footer addSubview:btn];
    footer.backgroundColor = [UIColor whiteColor];
    return footer;
}

@end



Cell里面

.h文件

@class <#type#>;

@interface <#type#> : UITableViewCell
+ (instancetype)cellWithTableView:(UITableView *)tableView;
@property (nonatomic, strong)<#type#> *model;

@end

.m文件

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"<#type#>";
    ProblemCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[<#type#> alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
} 


/**
 *  cell的初始化方法,一个cell只会调用一次
 *  一般在这里添加所有可能显示的子控件,以及子控件的一次性设置
 */
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

    }
    return self;
}    


- setModel:(<#type#>):model
{ 
        _model = model;
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 我们在上一篇《通过代码自定义不等高cell》中学习了tableView的相关知识,本文将在上文的基础上,利用sto...
    啊世ka阅读 1,561评论 2 7
  • *面试心声:其实这些题本人都没怎么背,但是在上海 两周半 面了大约10家 收到差不多3个offer,总结起来就是把...
    Dove_iOS阅读 27,222评论 30 472
  • 介绍 objc.io objc.io 是关于 Objective-C 最佳实践和先进技术的期刊,欢迎来到第一期! ...
    评评分分阅读 1,743评论 5 24
  • iOS网络架构讨论梳理整理中。。。 其实如果没有APIManager这一层是没法使用delegate的,毕竟多个单...
    yhtang阅读 5,295评论 1 23
  • 汽车在路上沉默地行驶。车子右拐驶上一条小路,从这条路可以更快地抄近道到达目的地。远处的集镇遍无烟火。本就人烟稀少,...
    猫猫猫猫先生阅读 406评论 0 0