//
//  ViewController.m
//  ZQRTableViewTest
//
//  Created by zzqqrr on 17/8/24.
//  Copyright (c) 2017年 zzqqrr. All rights reserved.
//

#import "ViewController.h"
#import "ZQRCarGroup.h"

@interface ViewController () <UITableViewDataSource>
@property (weak,nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong) NSArray *carGroups;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //设置数据源
    self.tableView.dataSource=self;
}

- (NSArray *)carGroups
{
    if(_carGroups==nil){
        ZQRCarGroup *model1=[[ZQRCarGroup alloc] init];
        model1.title=@"哈哈";
        model1.desc=@"呵呵";
        model1.cars=@[@"第一组第一行"];
        
        ZQRCarGroup *model2=[[ZQRCarGroup alloc] init];
        model2.title=@"哈哈";
        model2.desc=@"呵呵";
        model2.cars=@[@"第二组第一行",@"第二组第二行"];

        ZQRCarGroup *model3=[[ZQRCarGroup alloc] init];
        model3.title=@"哈哈";
        model3.desc=@"呵呵";
        model3.cars=@[@"第三组第一行",@"第三组第二行",@"第三组第三行"];
        _carGroups=@[model1,model2,model3];
    }
    return _carGroups;
}

/** 设置多少组组 */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.carGroups.count;
}
/** 指定组中的行 */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    ZQRCarGroup *group=self.carGroups[section];
    return group.cars.count;
}

/** 每一组显示的内容 */
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    ZQRCarGroup *group=self.carGroups[indexPath.section];
    NSString *strCar=group.cars[indexPath.row];
    cell.textLabel.text=strCar;
    return cell;
}
/** 头部文字 */
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    ZQRCarGroup *model=self.carGroups[section];
    return model.title;
}
/** 尾部文字 */
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
    ZQRCarGroup *model=self.carGroups[section];
    return model.desc;
}
@end

模型

//
//  ZQRCarGroup.h
//  
//
//  Created by zzqqrr on 17/8/25.
//
//

#import <Foundation/Foundation.h>

@interface ZQRCarGroup : NSObject
/**
 *头部标题
 */
@property (nonatomic,copy) NSString *title;
/**
 *尾部的描述
 */
@property (nonatomic,copy) NSString *desc;
/**
 *所有的信息列表
 */
@property (nonatomic,strong) NSArray *cars;
@end
//
//  ZQRCarGroup.m
//  
//
//  Created by zzqqrr on 17/8/25.
//
//

#import "ZQRCarGroup.h"

@interface ZQRCarGroup()

@end

@implementation ZQRCarGroup

@end