Watch 1 Star 0 Fork 0

AppleDream / UITableView2Objective-C

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
UITableView使用说明 spread retract

Clone or download
ViewController.m 2.31 KB
Copy Edit Web IDE Raw Blame History
AppleDream authored 2016-05-21 22:35 . 多组数据显示
// ViewController.m
// UITableView-多组数据显示
// Created by hyl on 16/5/21.
// Copyright © 2016年 hyl. All rights reserved.
#import "ViewController.h"
#import "HYLCar.h"
#import "HYLGroup.h"
@interface ViewController ()<UITableViewDataSource>
@property (nonatomic,strong) NSArray *groups;
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
#pragma mark - setter
-(NSArray *)groups{
if (_groups==nil) {
NSMutableArray *mGroups=[NSMutableArray array];
HYLGroup *group1=[[HYLGroup alloc]initWithHeadName:@"德系" footName:@"德系三强BBA还是ABB?"];[
[[HYLCar alloc]initWithName:@"宝马" icon:@"m_3_100"],
[[HYLCar alloc]initWithName:@"奥迪" icon:@"m_2_100"],
[[HYLCar alloc]initWithName:@"奔驰" icon:@"m_9_100"]
[mGroups addObject:group1];
HYLGroup *group2=[[HYLGroup alloc]initWithHeadName:@"天朝" footName:@"比亚迪还有哪些?"];[
[[HYLCar alloc]initWithName:@"比亚迪" icon:@"m_15_100"],
[[HYLCar alloc]initWithName:@"什么车" icon:@"m_16_100"]
[mGroups addObject:group2];
return _groups;
#pragma mark - <UITableViewDataSource>
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
return self.groups.count;
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.groups[section] cars].count;
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell=[[UITableViewCell alloc]init];
HYLGroup *group=self.groups[indexPath.section];
HYLCar *[indexPath.row];;
cell.imageView.image=[UIImage imageNamed:car.icon];
return cell;
-(NSString *) tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
HYLGroup *group=self.groups[section];
return group.footName;
-(NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
HYLGroup *group=self.groups[section];
return group.headName;

Comment ( 0 )

Sign in for post a comment