zoukankan      html  css  js  c++  java
  • UITableView

    一、表视图的结构

    1、表视图由头部视图、尾部视图、中间一连串单元格组成

    2、头部视图由tableHeaderView属性设置,尾部视图由tableFooterView属性设置

    3、分组表格由一连串section视图组成,每个section又包含一个连续的单元格

    4、每个section视图也有头部视图和尾部视图,通过委托方法设置

    二、tabview的初始化

    UITableView * tabView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, kDeviceWidth,kDeviceHeight) style:UITableViewStylePlain];

    三、tabview的属性

    _tableview=[[PullingRefreshTableView alloc]initWithFrame:CGRectMake(0, 0, kDeviceWidth, kDeviceHeight-64) pullingDelegate:self];
    _tableview.backgroundColor=[UIColor clearColor];
    _tableview.delegate=self;
    _tableview.dataSource=self;
    _tableview.tableFooterView=[[UIView alloc]initWithFrame:CGRectZero];
    [mainScroll addSubview:_tableview];

    四、tabview datasource必须实现的方法

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

      return [datasource count];

    }


    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    //根据标识去缓存池去取

    static NSString *mycell=@"cell";
    UITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:mycell ];

    //如果缓存池没有则重新创建并放到缓存池中
    if (cell==nil) {
    cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:mycell];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;

    UIImageView * leftImg=[[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 60, 50)];
    leftImg.backgroundColor=[UIColor clearColor];
    leftImg.tag=20;

    [cell.contentView addSubview:leftImg];

    return cell;

    }

     datasource 可选实现的方法

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    }

      //section中头部视图实现的标题

    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{

    }
    - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{

    }

    //指定单元格是否支持编辑

    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{

    }

    //指定单元格是否支持移动

    - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{

    }

    //右侧添加一个索引表

    - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{

    }

    //响应点击索引时的委托方法
    - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{

    }

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

    }

    - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{

    }

    五、tabview delegate

    //单元格的高度

    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 60;
    }

    //选中单元格的点击事件
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    }

    //设置头部、尾部视图的高度

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{}
    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{}

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section; // custom view for header. 
    - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section; // custom view for footer. 

  • 相关阅读:
    【洛谷P3992】开车
    Easyui datagrid+ashx 实现动态生成列
    SQL字符串处理函数大全
    在sqlserver中查找某个字段存在于那个表中的语句
    C# 合并图片
    JavaScript 监听屏幕滑动事件的JS
    JavaScript无提示关闭窗口(兼容IE/Firefox/Chrome)
    使用jquery插件实现图片延迟加载技术
    DataTable随机复制一行给新的DataTable
    MySQL恢复数据报错 #1289 The 'InnoDB' feature is disabled; you need MySQL built with 'InnoDB' to hav
  • 原文地址:https://www.cnblogs.com/momosmile/p/4641511.html
Copyright © 2011-2022 走看看