#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. CentOS 6.5 下安装 Kibana5

    1. 导入Elastic PGP Key 执行命令 rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch 2. 安装Kiban ...

  2. phpcms如何使用推荐位调用自定义字段

    默认phpcms是无法使用推荐位调用自定义字段的 一般自定义字段默认添加在附表里(也可以添加在主表里),调用自定义字段时 加上moreinfo="1" 直接写{pc:content ...

  3. ThinkPHP实现移动端访问自动切换主题模板

    ThinkPHP的模板主题机制,如果只是在PC,只要需修改 DEFAULT_THEME (新版模板主题默认是空,表示不启用模板主题功能)配置项就可以方便的实现多模板主题切换. 但对于移动端和PC端,也 ...

  4. EAS使用中FineUI的配置

    <?xml version="1.0" encoding="utf-8"?> <configuration> <configSec ...

  5. 如何将消息发送给Whatsapp联系人

    如何将消息发送给Whatsapp联系人 (由于本人喜欢word文档编辑,不喜欢网络编辑,所以仍然提供pdf版文档,方便查阅http://files.cnblogs.com/franksunny/sen ...

  6. 代码实现UI控件

    参考 Android 用纯代码实现复杂界面

  7. 4KB对齐

    4KB是固态硬盘的读写基本block size的大小也就是说读写的基本单位是4KB,哪怕1B的内容读写实际操作也是操作了4KB的块实际操作是以块为单位的 假设我的读写起始点刚好定在两个4KB大小的物理 ...

  8. Java Web应用调优线程池

    最简单的单线程 我们先从基础开始.无论使用哪种应用服务器或者框架(如Tomcat.Jetty等),他们都有类似的基础实现.Web服务的基础是套接字(socket),套接字负责监听端口,等待TCP连接, ...

  9. 理解Null,Undefined,NAN

    1.null表示尚未存在的对象,转为数值时为0.它表示"没有对象",即该处不应该有值,常用来表示函数企图返回一个不存在的对象.null是一种特殊的object(引用类型),代表一个 ...

  10. BZOJ3153 : Sone1

    Top Tree模板题,写起来真不是一般的蛋疼,调了两天.常数写渣了TAT Top Tree就是在LCT的基础上加以改动,将虚边也用splay维护, 对于A向儿子所连出去的虚边,用Splay维护↓ 为 ...