码迷,mamicode.com
首页 > 其他好文 > 详细

Day11

时间:2015-04-09 21:47:55      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

1 tableView 

   1.1设置组

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.carGroups.count;
}

 1.2 设置行

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    carGroup *group = [[carGroup alloc]init];
    group = self.carGroups[section];
    return group.cars.count;
}

   1.3 设置内容

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    carGroup *group = [[carGroup alloc]init];
    group = self.carGroups[indexPath.section];
    NSString *name = group.cars[indexPath.row];
    cell.textLabel.text = name;
    return cell;
}

1.4 设置头部

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    carGroup *group = [[carGroup alloc]init];
    group = self.carGroups[section];
    return group.title;
}

1.5 设置尾部

-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
    carGroup *group = [[carGroup alloc]init];
    group = self.carGroups[section];
    return group.desc;
}

1.6 tableView 样式

   1.6.1 UITableViewCellStyleDefault 单行简单样式

 

//
//  ViewController.m
//  tableViewDemo
//
//  Created by xin on 15/4/8.
//  Copyright (c) 2015年 Jackey. All rights reserved.
//

#import "ViewController.h"
#import "carGroup.h"

@interface ViewController ()<UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic,strong) NSArray *carGroups;
@end

@implementation ViewController

-(NSArray *)carGroups{
    if(_carGroups == nil){
        carGroup *group1 = [[carGroup alloc]init];
        group1.title = @"德系品牌";
        group1.desc = @"高端大气上档次";
        group1.cars = @[@"奥迪",@"宝马"];
        
        carGroup *group2 = [[carGroup alloc]init];
        group2.title = @"日韩品牌";
        group2.desc = @"牛逼哈哈";
        group2.cars = @[@"本田",@"丰田"];
        
        _carGroups = @[group1,group2];
    }
    
    return _carGroups;
}

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

#pragma mark - UITableViewDataSource
/*
 * 组
 */
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.carGroups.count;
}

/*
 * 行
 */
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    carGroup *group = [[carGroup alloc]init];
    group = self.carGroups[section];
    return group.cars.count;
}

/*
 * 设置标题
 */

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    carGroup *group = [[carGroup alloc]init];
    group = self.carGroups[section];
    return group.title;
}

/*
 * 设置foot
 */

-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
    carGroup *group = [[carGroup alloc]init];
    group = self.carGroups[section];
    return group.desc;
}

/*
 * 告知系统具体的行显示的内容
 */

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    carGroup *group = [[carGroup alloc]init];
    group = self.carGroups[indexPath.section];
    NSString *name = group.cars[indexPath.row];
    cell.textLabel.text = name;
    return cell;
}
@end

  

Day11

标签:

原文地址:http://www.cnblogs.com/lihaozhou/p/4411737.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!