【代码笔记】iOS-3个section,每个都有header.
来源:互联网 发布:域名投资的秘密 编辑:程序博客网 时间:2024/05/16 15:50
一,效果图:
二,工程目录。
三,代码
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;}
0 0
- 【代码笔记】iOS-3个section,每个都有header.
- 【代码笔记】iOS-一个tableView,两个section
- 关于UITableView中每个section的header显示
- iOS开发笔记--多个Section的TableView
- iOS开发笔记--多个Section的TableView
- iOS UICollectionView学习之二,纯代码实现布局,纯代码实现添加Section Header头部视图和 Section Footer尾部视图
- 共有5中颜色的球若干个,取3个球,每个颜色都不同,问有多少种取法;
- 有12个苹果,1只香蕉,分给3个小孩,每个小孩都必须最少分到一个水果,求能分多少种?
- 2018年,每个有追求的设计师都需要面对6个挑战
- 每个生命都有自己的形状
- 每个程序员都有自己的规则
- 每个网站都有固定的域名
- 每个线程都有一个堆栈。
- 每个对象都有一个接口
- 每个程序员都有一个孩子
- 1.2:每个对象都有一个接口
- 每个程序员都有责任去锻炼
- 每个语言都有自己的内涵
- 通达OA2015-缓存的使用
- Android中Context、Activity、Application之间有什么区别
- mappedBy的作用
- 十六进制直接转换成颜色的方法
- NSURLSession 数据解析
- 【代码笔记】iOS-3个section,每个都有header.
- 插入排序
- android定位相关
- 第13周 项目2-Kruskal算法的验证
- Scalaz(15)- Monad:依赖注入-Reader besides Cake
- ios中的开发一些小工具(就是一个写UIView的自定义组件的脱离环境,可以重新使用)解耦
- 关于第二次执行fragment+viewpager没有数据,页面空白的问题
- Unity uGui RawImage 渲染小地图
- 外企_IT代码民工四年的工作经验(实际可以算2年)