星空网 > 软件开发 > 操作系统

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

一,效果图:

 

【代码笔记】3个section,每个都有header.images/loading.gif' data-original="http://images2015.cnblogs.com/blog/337518/201510/337518-20151013102556647-1256142769.jpg" width="217" height="400" />

二,工程目录。

 

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

 

三,代码

 

RootViewController.h

 

【代码笔记】3个section,每个都有header.
#import <UIKit/UIKit.h>@interface RootViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>{  UITableView *MyTableView;}@end
【代码笔记】3个section,每个都有header.

 

RootViewController.m

 

【代码笔记】3个section,每个都有header.
#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;}
【代码笔记】3个section,每个都有header.

 

 




原标题:【代码笔记】3个section,每个都有header.

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

联邦快递FedEx:https://www.goluckyvip.com/news/113.html
Shopee台湾、马来、泰国、印尼热卖品盘点_Shopee暑假爆款特辑:https://www.goluckyvip.com/news/1130.html
Shopee与连连跨境支付正式达成战略合作!:https://www.goluckyvip.com/news/1131.html
进口商面临长达一个月的延误、运费成本却增加两倍的打击:https://www.goluckyvip.com/news/113145.html
独立站优秀案例分析:礼品盒品牌如何提高平均客单价?:https://www.goluckyvip.com/news/113146.html
Shopee和印尼电商公司的增长和盈利策略:https://www.goluckyvip.com/news/113147.html
宜宾江安-宜宾江安县旅游景点大全:https://www.vstour.cn/a/404232.html
浏阳市里面哪里好玩的地方 浏阳市内有什么好玩的地方:https://www.vstour.cn/a/404233.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流