#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的更多相关文章

  1. UITableView延伸:点击cell关闭键盘,加载不同cell,监听里面的textfeild内容改变

    其实点击cell关闭键盘只要一句话 - () {         cell = [tableView dequeueReusableCellWithIdentifier:){         cell ...

  2. 后台找到repeater里面的div并添加客户端点击事件

    public partial class Inv_SelectWorkservice : System.Web.UI.Page,IPostBackEventHandler{ } 通过OnItemCre ...

  3. 关于ES7里面的async和await

    async / await是ES7的重要特性之一,也是目前社区里公认的优秀异步解决方案.目前,async / await这个特性已经是stage 3的建议,可以看看TC39的进度,本篇文章将分享asy ...

  4. m_Orchestrate learning system---二十四、thinkphp里面的ajax如何使用

    m_Orchestrate learning system---二十四.thinkphp里面的ajax如何使用 一.总结 一句话总结:其实ajax非常简单:前台要做的事情就是发送ajax请求过来,后台 ...

  5. Activity往另外一个Activity传值,Fragment获取另外一个Activity里面的值。

    在oneActivity中实现跳转到MainActivity //intent 用来跳转另外一个MainActivity,bundle传值到MainActivity         Intent Ma ...

  6. Java基本概念(2)J2EE里面的2是什么意思

    J2EE里面的2是什么意思 J2SE,J2SE,J2ME中2的含义要追溯要1998年.1998年Java 1.2版本发布,1999年发布Java 1.2的标准版,企业版,微型版三个版本,为了区分这三个 ...

  7. ListView中动态显示和隐藏Header&Footer

    ListView的模板写法 ListView模板写法的完整代码: android代码优化----ListView中自定义adapter的封装(ListView的模板写法) 以后每写一个ListView ...

  8. 在wex5平台grid里面的gridselect下拉不能显示汉字问题

    当grid里面有gridSelect组件的时候,gridSelect里面的bind-ref是对应的数据库存入字段(int类型),bind-labelRef是对应的计算字段(视图里面的),而option ...

  9. dede文章调用时过滤调 body里面的style属性和值

    dede 发布文章的时候会在里面的标签中添加一些style 属性,现在改网站想去掉这些属性和里面的值,因为文章太多所以就用下面的方法 \include\arc.listview.class.php 在 ...

随机推荐

  1. hadoop配置文件加载顺序(转)

    原文  http://www.cnblogs.com/wolfblogs/p/4147485.html 用了一段时间的hadoop,现在回来看看源码发现别有一番味道,温故而知新,还真是这样的 在使用h ...

  2. Linux 查看 网卡类型

    http://blog.csdn.net/ydyang1126/article/details/51140131 http://blog.sina.com.cn/s/blog_5425edf40101 ...

  3. InnoDB引擎的索引和存储结构

    在Oracle 和SQL Server等数据库中只有一种存储引擎,所有数据存储管理机制都是一样的.而MySql数据库提供了多种存储引擎.用户可以根据不同的需求为数据表选择不同的存储引擎,用户也可以根据 ...

  4. jquery easy ui 1.3.4 数据表格(DataGrid)(8)

    8.1.创建DataGrid html代码 <table id="dg"></table> $("#dg").datagrid({ // ...

  5. Java Hour 45 Hibernate ( 2 )

    基本确定了,一个月后也就是在2014年的开端,我将离开这个公司. 所以我大概还有30个学时. 45.1 你需要一个数据库 首先,必须有一个试验用的数据库,这里我们使用MySQL. 尽管书中的说明是使用 ...

  6. 14、Silverlight 滤镜到 UWP 滤镜的移植(二)

    上一篇文章 大致介绍了,移植戴震军大哥的 Windows Phone7 中,对于高斯模糊滤镜的移植,主要是 int[] 数组和 byte[] 数组的互相转换.同样的思路,只要把前文的方法封装一下,就能 ...

  7. jquery日期格式化

    function dateFormat(date, format){     date = , ) / ), ) {                 v = );             }      ...

  8. Codeforces Round #Pi (Div. 2) C. Geometric Progression map

    C. Geometric Progression Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  9. 全自动编译FFmpeg(含x264,fdk aac,libmp3lame,libvpx等第3方库)

    需要修改 #存放下载的源代码目录compile_dir=/root/ffmpeg_compile #库文件安装目录prefix_dir=/mnt/third-party 运行方法: source ce ...

  10. 转-CSS3 圆角(border-radius)

    CSS3 圆角(border-radius)   前缀 例1 例2:无边框 书写顺序 其它 支持性 值:半径的长度 前缀 -moz(例如 -moz-border-radius)用于Firefox -w ...