#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. 制做RPM包

    http://nmshuishui.blog.51cto.com/1850554/1583117 [root@NGM ~]# yum install pcre-devel zlib-devel ope ...

  2. MVC @helper (转载)

    转载地址:http://gaoling386.blog.163.com/blog/static/5404602420130595842894/ ASP.NET MVC 3支持一项名为“Razor”的新 ...

  3. php动态安装mongo扩展

    首先下载mongo扩展包  http://pecl.php.net/package/mongo 开始安装把 wget http://pecl.php.net/get/mongo-1.5.8.tgz t ...

  4. Sql server之路 (四)添加本地数据库MDF文件

    安装环境 VS2008  Vs2008 Sp1 安装系统 Win8 1.创建窗体 右键添加新项 上一步 上一步 点击确定 双击Database1.mdf文件 在列名出填写字段名 保存 Ctrl+S 点 ...

  5. Sql server之路 (六)上传服务器图片

    原理: 上传图片的名字 插入到数据库里 上传图片的内容(二进制数据) 写到服务器指定的目录下 下次读取图片的时候 从数据库里的指定字段里读取图片文件名 从数据库的指定路径下 拼串成完成的路径 就可以下 ...

  6. codeiginter框架数据库操作

       /**      *  //查询表内的数据      *  $res = $this->db->get('表名');      *  $res->result();       ...

  7. TypeScript的崛起

    今天要讨论的话题是TypeScript.之前在微博上转载过一篇<The Rise of TypeScript?>的文章,今天来谈一下我的感想. 很多朋友应该都了解,TypeScript是微 ...

  8. BZOJ 1029: [JSOI2007]建筑抢修 堆+贪心

    1029: [JSOI2007]建筑抢修 Description 小刚在玩JSOI提供的一个称之为“建筑抢修”的电脑游戏:经过了一场激烈的战斗,T部落消灭了所有z部落的入侵者.但是T部落的基地里已经有 ...

  9. 水题 ZOJ 3869 Ace of Aces

    题目传送门 水题,找出出现次数最多的数字,若多个输出Nobody //#include <bits/stdc++.h> //using namespace std; #include &l ...

  10. HDU3586 Information Disturbing(树形DP)

    题目大概说一棵树有边权,要删掉一些边,使叶子到达不了树根1且删掉边的权和小于等于m,问删掉边中最大权的最小值能是多少. 考虑问题规模,与转移的时间复杂度,用这么个状态dp: dp[u][k]表示在u结 ...