【代码笔记】3个section,每个都有header.

一,效果图:

二,工程目录。

三,代码

RootViewController.h

#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController
<UITableViewDataSource,UITableViewDelegate>
{
    UITableView *MyTableView;
}
@end

RootViewController.m

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    //更新背景图
    [self initBackGroundView];
}
#pragma -mark -functions
-(void)initBackGroundView
{
    //tableView
    MyTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, 400) style:UITableViewStylePlain];
    MyTableView.delegate=self;
    MyTableView.dataSource=self;
    [self.view addSubview:MyTableView];
}
#pragma -mark -UITableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 105;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"ID"];
    if ( cell== nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"ID"];
    }
    if (indexPath.section==0) {
        [email protected]"0";
        cell.backgroundColor=[UIColor greenColor];

    }
    else if(indexPath.section==1)
    {
        [email protected]"1";
        cell.backgroundColor=[UIColor redColor];
    }
    else if(indexPath.section==2)
    {
        [email protected]"2";
        cell.backgroundColor=[UIColor orangeColor];
    }
    return cell;

}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)];
    view.backgroundColor=[UIColor blackColor];

    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, 30)];
    label.backgroundColor=[UIColor clearColor];
    label.textColor=[UIColor whiteColor];
    if (section==0) {
        [email protected]"电影";
    }else if(section==1)
    {
        [email protected]"电视剧";
    }else if(section==2)
    {
        [email protected]"动漫";
    }
    [view addSubview:label];
    return  view;
}

时间: 2024-08-13 19:16:34

【代码笔记】3个section,每个都有header.的相关文章

TableView有3个section,每个都有header.同时EGOTableViewPullRefresh刷新数据

效果图: 代码: .h #import <UIKit/UIKit.h> #import "EGORefreshTableHeaderView.h" @interface RootViewController : UIViewController <UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate,EGORefreshTableHeaderDelegate> { UITableView *

多线程二(GCD)代码笔记

// // TWFXViewController.h // Demo_GCD // // Created by Lion User on 12-12-11. // Copyright (c) 2012年 Lion User. All rights reserved. // #import <UIKit/UIKit.h> @interface TWFXViewController : UIViewController @property (retain, nonatomic) IBOutlet

汇编代码笔记 动态更新中

汇编考完了,悲剧的93分,,,,,以后的汇编就用的少了,凡是用到都来这里做点代码笔记: 一.错误总结: 1.程序最后END +起始标号,否则U的时候需要自己手动找起始位置而且有可能程序翻译指令错误 2.对内存单元进行操作的时候,注意类型的指定,比如inc [si]必然是错的因为没有类型,还有处理数据计数器si注意加一 3.凡是用到[si]这种形式的,都注意声明BYTEPTR,WORD PTR 4.同3的错误,如果声明了COUNTDB 3,那么mov cx,count就是不对的,因为类型不匹配 5

《linux 内核完全剖析》 vsprintf.c 代码笔记

Flex1 到 Flex3 使用的都是 Halo组件,这里将介绍Halo 组件中的List 和 DataGrid .其中 DataGrid 是显示多列数据中最常用的方式.但是在Spark中还有没对应DataGrid的组件. 先写个"食物"的模型 Dinner.as . package model { [Bindable] public class Dinner { public var name:String; public var food:String; public var du

前端努力的哪怕从代码的体积哪怕是20K都在努力减少的同时

久以前在安卓2.0系统刚刚的时候就对HTML5比较关注!因为我也是那个时候刚刚入行做前端的.那个时候最大的乐趣就是看着w3plus上面各种css3的效果,觉得哇,好牛逼原来可以这样做,然后3年过去了...手上的APP做完的没有40个也有30个了!然后去年参加了HTML5峰会.听着一批前辈们说着他们在html5的道路中遇到的挫折,经验,以及流行的框架,制作HTML5的ide...也算是小有经验了!...然后知道的越多,现实就越残酷(大漠竟然说他不会JS,无语偶曾经的偶像竟然说他真的不会js还发誓!

Effective Java读书笔记(3对于所有对象都通用的方法)

3.1 覆盖equals时请遵守通用约定 什么时候应该覆盖Object.equals()方法呢? 如果类具有自己特有的"逻辑相等"概念(不同于对象等同的概念),而且超类还没有覆盖equals以实现期望的行为,这时我们就需要覆盖equals方法. Object.equals()方法具有自反性.对称性.传递性.一致性和与null比较返回false的特点. 实现高质量equals方法的诀窍: (1)使用==操作符检查"参数是否为这个对象的引用".如果是,则返回true,这

JfinalUIB 代码笔记 (4)--- 高仿ibatis(mybatis)实现sql的集中管理

实现sql的集中管理,简单的把一些固定长度的sql移植进xml很简单,这没有什么好多说的,关键问题是我们平时处理的sql,有大量是动态长度的,比如说最常见的就是多条件的分页查询,往往我们会在代码中写大量的if else,想把这些移植进xml就比较困难了,完全仿制ibatis来做xml标签工作量太大,最省事的处理方法就是能不能直接把Java代码的逻辑处理方式移植进xml,然后对逻辑代码进行解析,绕开那一大堆的xml标签定义,下面就是jfinaluib中的处理方式: 1.0 暂时还是用的拼接,没有预

E:Encountered a section with no Package: header, E:Problem with MergeList /var/lib/apt/lists/******

最近在Ubuntu上安装mysql-server时用命令apt-get install mysql-server出现报错提示: E:Encountered a section with no Package: header, E:Problem with MergeList /var/lib/apt/lists/****** 回想起上一次调用apt-get update时由于update时间太长我直接CTRL+C中止的情形,可能是由于lists中某一个文件没有下载完成,出现解析错误. 可用的解决

Ubuntu 16.04错误:正在读取软件包列表... 有错误! E: Encountered a section with no Package: header E: Problem with MergeList /var/lib/apt/lists/ppa.launchpad.net_t-tujikawa_ppa_ubuntu_dists_xenial_main_i18n_Translatio

错误: 正在读取软件包列表... 有错误! E: Encountered a section with no Package: header E: Problem with MergeList /var/lib/apt/lists/ppa.launchpad.net_t-tujikawa_ppa_ubuntu_dists_xenial_main_i18n_Translation-en E: 无法解析或打开软件包的列表或是状态文件. 解决方法: 1.删除上面提示的PPA源,再找到新的源添加.比如直

解决E: Encountered a section with no Package: header

解决E: Encountered a section with no Package: header错误 我的ubuntu机器上出现下面这个错误. Reading package lists... Error! E: Encountered a section with no Package: header E: Problem with MergeList /var/lib/apt/lists/ftp.sjtu.edu.cn_ubuntu_dists_precise-security_rest