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 在 ...
随机推荐
- Maven使用笔记(四)pom.xml配置详解
pom.xml文件配置详解 --声明规范 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=" ...
- ytu 1937:查找最大元素(水题)
查找最大元素 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 51 Solved: 23[Submit][Status][Web Board] Descr ...
- 无需u盘和光盘安装linux
今天折腾linux引导的时候发现一个不用任何移动介质的linux安装方法,即直接在硬盘中启动安装系统. 1.首先下载一个easyBCD.进入“添加新条目”选项选择“NeoGrub”条目,然后选择“添加 ...
- jquery 展开折叠菜单
jquery 展开折叠菜单 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <ht ...
- RTP与RTCP协议介绍
转自:http://zhangjunhd.blog.51cto.com/113473/25481/ 本文主要介绍RTP与RTCP协议. author: ZJ 06-11-17 Blog: [url ...
- Striiv Myland 攻略
推荐一款IOS平台上的运动APP:Striiv.可以记录平时的步数,路程,卡路里,运动时间.如果购买相应的硬件,还可以记录每天爬了多少台阶(这是专门为爬楼者用的么...). 其中比较吸引我的是里面有个 ...
- Android Studio 1.0首次安装遇到的问题,无法下载SDK
相信,在安装Android Studio的过程中会遇到很多问题,特别是第一次启动下载不了sdk.郁闷了吧. 可以去官网下载,也可以点击这里下载Android Studio和sdk. 一.不下载SDK启 ...
- GPS基础
public class MainActivity extends Activity { private LocationManager manager; private List<String ...
- UVa11324 The Largest Clique(强连通分量+缩点+记忆化搜索)
题目给一张有向图G,要在其传递闭包T(G)上删除若干点,使得留下来的所有点具有单连通性,问最多能留下几个点. 其实这道题在T(G)上的连通性等同于在G上的连通性,所以考虑G就行了. 那么问题就简单了, ...
- Ubuntu14.04 Server amd64 配置 Apache+MySQL+Django
写在前面 因为不同版本的apache等软件文件夹和配置文件的名称设置都不尽相同,网上累死累活查了好多个博客就没一个能成功配出来的. 所以本文也不一定能帮到你,请在确定对自己有用之前不要盲目转载,以免给 ...