【代码笔记】iOS-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) {
cell.textLabel.text=@"0";
cell.backgroundColor=[UIColor greenColor]; }
else if(indexPath.section==1)
{
cell.textLabel.text=@"1";
cell.backgroundColor=[UIColor redColor];
}
else if(indexPath.section==2)
{
cell.textLabel.text=@"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) {
label.text=@"电影";
}else if(section==1)
{
label.text=@"电视剧";
}else if(section==2)
{
label.text=@"动漫";
}
[view addSubview:label];
return view;
}

【代码笔记】iOS-3个section,每个都有header.的更多相关文章
- Masonry -- 使用纯代码进行iOS应用的autolayout自适应布局
简介 简化iOS应用使用纯代码机型自适应布局的工作,使用一种简洁高效的语法替代NSLayoutConstraints. 项目主页: Masonry 最新示例: 点击下载 项目简议: 如果再看到关于纯代 ...
- 【hadoop代码笔记】Mapreduce shuffle过程之Map输出过程
一.概要描述 shuffle是MapReduce的一个核心过程,因此没有在前面的MapReduce作业提交的过程中描述,而是单独拿出来比较详细的描述. 根据官方的流程图示如下: 本篇文章中只是想尝试从 ...
- 【hadoop代码笔记】hadoop作业提交之汇总
一.概述 在本篇博文中,试图通过代码了解hadoop job执行的整个流程.即用户提交的mapreduce的jar文件.输入提交到hadoop的集群,并在集群中运行.重点在代码的角度描述整个流程,有些 ...
- 笔记-iOS 视图控制器转场详解(上)
这是一篇长文,详细讲解了视图控制器转场的方方面面,配有详细的示意图和代码,为了使得文章在微信公众号中易于阅读,seedante 辛苦将大量长篇代码用截图的方式呈现,另外作者也在 Github 上附上了 ...
- IOS开发笔记 IOS如何访问通讯录
IOS开发笔记 IOS如何访问通讯录 其实我是反对这类的需求,你说你读我的隐私,我肯定不愿意的. 幸好ios6.0 以后给了个权限控制.当打开app的时候你可以选择拒绝. 实现方法: [plain] ...
- <Python Text Processing with NLTK 2.0 Cookbook>代码笔记
如下是<Python Text Processing with NLTK 2.0 Cookbook>一书部分章节的代码笔记. Tokenizing text into sentences ...
- Masonry — 使用纯代码进行iOS应用的autolayout自适应布局
本文转载至 http://www.ios122.com/2015/09/masonry/ 简化iOS应用使用纯代码机型自适应布局的工作,使用一种简洁高效的语法替代NSLayoutConstrain ...
- [学习笔记] SSD代码笔记 + EifficientNet backbone 练习
SSD代码笔记 + EifficientNet backbone 练习 ssd代码完全ok了,然后用最近性能和速度都非常牛的Eifficient Net做backbone设计了自己的TinySSD网络 ...
- 代码中,使用__DATE__宏,获取程序编译时间,如何保证每次编译代码(非重新生成方式),都能更新__DATE__的值?
代码中,使用__DATE__宏,获取程序编译时间,如何保证每次编译代码(非重新生成方式),都能更新__DATE__的值? 解决:通过vs的预先生成命令中,添加批处理命令,删除对应的obj文件方式,强制 ...
随机推荐
- If WCF Service side and Client side config is different?!
from stackoverflow http://stackoverflow.com/questions/4879310/when-setting-up-a-wcf-client-and-serve ...
- 【转】ASP.NET"正在中止线程"错误原因
最近做的系统中老出现的一些问题不太明白,在使用 Response.End.Response.Redirect 或 Server.Transfer 时出现 ThreadAbortException , ...
- IBM和传统IT的沦落
传统IT厂商沦落已经成为一种趋势.不仅仅是在中国去IOE的大背景下,在全球范围内,这些曾经盛极一时的IT大鳄也在衰落.作为一个在IBM服务了将近14年的老员工,我想浅谈一下IBM以及整个传统IT行业的 ...
- 【Java每日一题】20161123
package Nov2016; import java.util.Scanner; public class Ques1123 { public static void main(String[] ...
- 代码与图详解性能之Python集合类型(list tuple dict set generator)
Python内嵌的集合类型有list.tuple.set.dict. 列表list:看似数组,但比数组强大,支持索引.切片.查找.增加等功能. 元组tuple:功能跟list差不多,但一旦生成,长度及 ...
- 高性能的分布式服务框架 Dubbo
我思故我在,提问启迪思考! 1. 什么是Dubbo? 官网:http://dubbo.io/,DUBBO是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及作为SOA服务治理的 ...
- [moka同学笔记]window下.htacess文件 与linux下.htacess文件
windows下 # Turn on URL rewritingRewriteEngine On# Installation directoryRewriteBase /# Protect hidde ...
- mysql安装中出现的问题,
花了一天的时间明天mysql的安装方法: 自己的错误: 主要原因: (1):bin文件坏境配置出现了问题,没有重新在系统中配置文件 解决方法:右击电脑——属性——高级系统设置——变量配置——在path ...
- No suitable driver found for jdbc:mysql://localhost:3306/dmc
1. 使用java jdbc直接连接数据库操作, 出现题中错误, 参考网上说法, 将mysql连接jar放入jre拓展底下 不再报错
- PLSQL怎样导出oracle表结构和数据
1.导出表结构和数据方式1.tools->export user objects是导出表结构 tools ->export user object 选择选项,导出.sql文件 说明:导出的 ...