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 [email protected][@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18"];
    self.view.backgroundColor = [UIColor grayColor];
    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 30)];
    label.text =@"ffff";
    label.textColor =[UIColor blackColor];
    headerView =[[UIView alloc]initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width,100)];
    headerView.backgroundColor =[UIColor greenColor];
    [headerView addSubview:label];
    [self.view addSubview:headerView];

    table = [[UITableView alloc]initWithFrame:CGRectMake(0, 174, [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 2;
}
-(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 50;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 50;
}
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{

    if (section==0) {

    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 50)];
    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(0, 0, 100, 50)];
        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==0) {
        UIView *Iview =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 50)];
        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(0, 0, 200, 50)];
        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 == 100102) {
        UITableView *tableview = (UITableView *)scrollView;
        CGFloat sectionHeaderHeight = 200;
        CGFloat sectionFooterHeight = 10;
        CGFloat offsetY = tableview.contentOffset.y;
        if (offsetY >= 0 && offsetY <= sectionHeaderHeight)
        {
            tableview.contentInset = UIEdgeInsetsMake(-offsetY, 0, -sectionFooterHeight, 0);
        }else if (offsetY >= sectionHeaderHeight && offsetY <= tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight)
        {
            tableview.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, -sectionFooterHeight, 0);
        }else if (offsetY >= tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight && offsetY <= tableview.contentSize.height - tableview.frame.size.height)
        {
            tableview.contentInset = UIEdgeInsetsMake(-offsetY, 0, -(tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight), 0);
        }
    }
}

支持MJRefresh刷新可在header里面添加 滚动视图  footer里面添加按钮

时间: 2024-08-09 06:34:47

UItableview里面的header、footer的相关文章

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

public partial class Inv_SelectWorkservice : System.Web.UI.Page,IPostBackEventHandler{ } 通过OnItemCreated 找到repeater里面的div并添加客户端点击事件div要加上runat="server" id="itemTy" onclick="test" 后台: protected void Repeater2_ItemCreated(objec

Afianl框架里面的FinalBitmap加载网络图片

在Afianl框架里,FinalBitmap如何加载网络图片?有什么简单的方法吗?现在让麦子学院的android开发老师讲讲afina框架里面的finalbitmap加载网络图片的方法,Afinal里边FinalBitmap:用于显现bitmap图像,而无需思考线程并发和oom等疑问. 1.测验恳求 运用页面翻开http://avatar.csdn.net/C/6/8/1_bz419927089.jpg"可以看到一张图像. 2.新建FinalBitmap目标 1 FinalBitmap bitm

函数的上下文就是函数里面的this是谁

规律1:函数用圆括号调用,函数的上下文是window对象 比如小题目: function fun(){ var a = 888; alert(this.a); //实际上访问的是window.a } var a = 666; fun(); //弹出666 函数function fun(){}的上下文是什么!不要看它怎么定义,要看它怎么调用!!此时是fun()函数名加上圆括号直接调用,此时上下文就是window对象! 而我们知道:所有的全局变量都是window对象的属性,(注意:函数里面的局部变量

如何去除项目里面的SVN和CVS文件夹

SVN和CVS是我们常使用的项目版本管理工具,为我们的工作带来了很大的方便.但是,有时候我们需要删除里面的SVN和CVS文件夹. 1 如何快速的删除项目中的版本控制文件夹  (1) 删除项目中的SVN文件夹.我们可以使用bat脚本来实现快速递归删除,代码如下: @echo off echo Deleting SVN folders and files under: %1 REM Open Folder specified by parameter. cd %1 REM Recursive del

提取数据库字段里面的值,并改变+图片懒加载,jquery延迟加载

要求:手机端打开某个页面的详细信息,因为网速或者别的原因,响应太慢,因为图片大的原因,希望先进来,图片在网页运行的情况再慢慢加载(jquer延迟加载) http://www.w3cways.com/1765.html()  困难:因为页面的图片是用编辑器加进去的        :图片与文字存到数据库的字段中 :实现思路:从数据库中读取这个字段,把字段里面的src替换成lazyload 然后再返回给页面 这里主要讲是怎么把从数据库取到的数据里面的字段里面的值替换然后与页面直接的数据转换 首先 pu

直接修改别人jar包里面的class文件 工具:jclasslib

出于某些原因 需要把别人jar包里面的class修改一下信息 配置文件*.properties MANIFEST.MF 这些东西可以直接用记事本打开修改 然后替换掉就OK.. 在网上游荡了半天,没有找到合适的方法 开始我是先用jd-gui反编译 把我需要修改的那个A.class文件反编译出来把代码保存到A.Java 然后直接在dos里面用javac A.java编译 问题来了.. 因为A.java引用了很多其他jar下面的方法 而且A.java有package 鼓捣了半天以后 最终结果:编译无法

form里面的action和method(post和get的方法)使用

一.form里面的action和method的post使用方法 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="formsubmitpost.aspx.cs" Inherits="formsubmitpost" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xh

gdb 和 addr2line 调试 crash(包含如何调试so里面的crash)

嵌入式编程中会遇到各种crash的问题. 对于这样的问题,有两种调试方法: addr2line  和 gdb. 第一章   先讲解下gcc 编译加不加 -g 对程序的影响, 还有strip. //1.1.cpp #include <iostream> using namespace std; bool IsUnique() {         int k = 0, m = 0;         k = k/m;      //这里会crash         return true; } in

设置UITableview 浮动的 header

Group时在viewForHeaderInSection设置时是固定的,简单的方法,设置成Plain就可以了.有好方法后面还会更新.设置UITableview 浮动的 header,布布扣,bubuko.com