UItableview里面的header、footer
#import "ViewController.h"
#import "MJRefresh.h"
@interface ViewController ()
{
UITableView *table;
NSArray * arr;
UIView * headerView;
}
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
arr =@[@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@""];
self.view.backgroundColor = [UIColor grayColor];
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(, , , )];
label.text =@"ffff";
label.textColor =[UIColor blackColor];
headerView =[[UIView alloc]initWithFrame:CGRectMake(, , [UIScreen mainScreen].bounds.size.width,)];
headerView.backgroundColor =[UIColor greenColor];
[headerView addSubview:label];
[self.view addSubview:headerView]; table = [[UITableView alloc]initWithFrame:CGRectMake(, , [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) style:UITableViewStylePlain];
table.delegate = self;
table.dataSource = self; [table.mj_header beginRefreshing];
table.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(downRefresh)]; table.backgroundColor = [UIColor cyanColor];
[self.view addSubview:table]; } -(void)downRefresh{
[table.mj_header endRefreshing]; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return arr.count;
} -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return ;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = arr [indexPath.row];
return cell;
} //-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
//
// return @"为什么";
//}
// -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return ;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return ;
}
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ if (section==) { UIView * view = [[UIView alloc]initWithFrame:CGRectMake(, , , )];
view.backgroundColor = [UIColor redColor];
UILabel * footerlabel = [[UILabel alloc]initWithFrame:view.frame];
footerlabel.text = @"footer1";
footerlabel.textAlignment = NSTextAlignmentCenter;
[view addSubview:footerlabel];
return view;
}
else{
UIView * view = [[UIView alloc]initWithFrame:CGRectMake(, , , )];
UILabel * footerlabel = [[UILabel alloc]initWithFrame:view.frame];
footerlabel.text = @"footer2";
view.backgroundColor = [UIColor redColor];
footerlabel.textAlignment = NSTextAlignmentCenter;
[view addSubview:footerlabel];
return view; }
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ if (section==) {
UIView *Iview =[[UIView alloc]initWithFrame:CGRectMake(, , , )];
Iview.backgroundColor =[UIColor orangeColor];
UILabel * footerlabel = [[UILabel alloc]initWithFrame:Iview.frame];
footerlabel.text = @"header1";
footerlabel.textAlignment = NSTextAlignmentCenter;
[Iview addSubview:footerlabel];
return Iview;
}
else{
UIView *Iview =[[UIView alloc]initWithFrame:CGRectMake(, , , )];
Iview.backgroundColor =[UIColor cyanColor];
UILabel * footerlabel = [[UILabel alloc]initWithFrame:Iview.frame];
footerlabel.text = @"header2";
footerlabel.textAlignment = NSTextAlignmentCenter;
[Iview addSubview:footerlabel];
return Iview; } } -(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.tag == ) {
UITableView *tableview = (UITableView *)scrollView;
CGFloat sectionHeaderHeight = ;
CGFloat sectionFooterHeight = ;
CGFloat offsetY = tableview.contentOffset.y;
if (offsetY >= && offsetY <= sectionHeaderHeight)
{
tableview.contentInset = UIEdgeInsetsMake(-offsetY, , -sectionFooterHeight, );
}else if (offsetY >= sectionHeaderHeight && offsetY <= tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight)
{
tableview.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, , -sectionFooterHeight, );
}else if (offsetY >= tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight && offsetY <= tableview.contentSize.height - tableview.frame.size.height)
{
tableview.contentInset = UIEdgeInsetsMake(-offsetY, , -(tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight), );
}
}
}
支持MJRefresh刷新可在header里面添加 滚动视图 footer里面添加按钮

UItableview里面的header、footer的更多相关文章
- UITableView延伸:点击cell关闭键盘,加载不同cell,监听里面的textfeild内容改变
其实点击cell关闭键盘只要一句话 - () { cell = [tableView dequeueReusableCellWithIdentifier:){ cell ...
- 后台找到repeater里面的div并添加客户端点击事件
public partial class Inv_SelectWorkservice : System.Web.UI.Page,IPostBackEventHandler{ } 通过OnItemCre ...
- 关于ES7里面的async和await
async / await是ES7的重要特性之一,也是目前社区里公认的优秀异步解决方案.目前,async / await这个特性已经是stage 3的建议,可以看看TC39的进度,本篇文章将分享asy ...
- m_Orchestrate learning system---二十四、thinkphp里面的ajax如何使用
m_Orchestrate learning system---二十四.thinkphp里面的ajax如何使用 一.总结 一句话总结:其实ajax非常简单:前台要做的事情就是发送ajax请求过来,后台 ...
- Activity往另外一个Activity传值,Fragment获取另外一个Activity里面的值。
在oneActivity中实现跳转到MainActivity //intent 用来跳转另外一个MainActivity,bundle传值到MainActivity Intent Ma ...
- Java基本概念(2)J2EE里面的2是什么意思
J2EE里面的2是什么意思 J2SE,J2SE,J2ME中2的含义要追溯要1998年.1998年Java 1.2版本发布,1999年发布Java 1.2的标准版,企业版,微型版三个版本,为了区分这三个 ...
- ListView中动态显示和隐藏Header&Footer
ListView的模板写法 ListView模板写法的完整代码: android代码优化----ListView中自定义adapter的封装(ListView的模板写法) 以后每写一个ListView ...
- 在wex5平台grid里面的gridselect下拉不能显示汉字问题
当grid里面有gridSelect组件的时候,gridSelect里面的bind-ref是对应的数据库存入字段(int类型),bind-labelRef是对应的计算字段(视图里面的),而option ...
- dede文章调用时过滤调 body里面的style属性和值
dede 发布文章的时候会在里面的标签中添加一些style 属性,现在改网站想去掉这些属性和里面的值,因为文章太多所以就用下面的方法 \include\arc.listview.class.php 在 ...
随机推荐
- 【转】Quartus II调用modelsim无缝仿真
Quartus II调用modelsim无缝仿真 ★emouse 思·睿博客文章★ 原创文章转载请注明:http://emouse.cnblogs.com 本篇文章为转载,写的不错,最近在学mode ...
- sdut 2416:Fruit Ninja II(第三届山东省省赛原题,数学题)
Fruit Ninja II Time Limit: 5000MS Memory limit: 65536K 题目描述 Have you ever played a popular game name ...
- HTML5小游戏【是男人就下一百层】UI美化版
之前写的小游戏,要么就比较简单,要么就是比较难看,或者人物本身是不会动的. 结合了其它人的经验,研究了一下精灵运动,就写一个简单的小游戏来试一下. 介绍一下几个主要的类: Frame:帧的定义,主要描 ...
- php数据库操作封装类
<?php /** * Desc: php操作mysql的封装类 * Author zhifeng * Date: 2015/04/15 * 连接模式:PDO */ class MMysql { ...
- Loadrunner中web_custom_request使用场景
其中有一段从服务器段动态返回的字符串需要重新提交给服务器(见红色标注) 录制自动生成的脚本是: web_submit_data("generateYfLstAction.do", ...
- Linux常用命令_(基本命令)
基本命令:ls.cd.pwd.man 1.ls 打印当前目录下的文件和目录文件 用法详解:: ls [-alFR] [文件或目录] -a 显示所有文件,包括隐藏文件:[root@qmfsun]#ls ...
- WebForms UnobtrusiveValidationMode 需要“jquery”ScriptResourceMapping
我百度到的答案,原文请点击 错误信息: WebForms UnobtrusiveValidationMode 需要“jquery”ScriptResourceMapping.请添加一个名为 jquer ...
- ZOJ3791 An Easy Game(DP)
给两个长n的01串s1和s2,要对s1进行k次修改,每次修改m个不同位置,问有几种方式修改成s2. 想偏了,只想到原始的01数值是不重要的,因为每个位置修改次数的奇偶性是确定的这一层.. 其实,这题只 ...
- 【python游戏编程之旅】第三篇---pygame事件与设备轮询
本系列博客介绍以python+pygame库进行小游戏的开发.有写的不对之处还望各位海涵. 在上一篇博客中,我们学习了pygame中的IO.数据http://www.cnblogs.com/msxh/ ...
- JavaScript,一个超级简单的方法判断浏览器的内核前缀
先说明,此处的方法是说超级简单的方法,不是指代码超级少,而是用非常简单的知识点,只要懂得怎么写JavaScript的行内样式就可以判断. 大家应该还记得JavaScript行内样式怎么写吧?(看来我是 ...