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. 

  • 相关阅读:
    YOLOv5实现自定义对象训练与OpenVINO部署全解析
    GMS程序调试指南GMS-Feature-Matcher
    MobileNet V3与Lite R-ASPP 总结
    codevs 3385 拯救Oier(一) Save Oier—first
    喵哈哈村的魔法考试 Round #6 (Div.3) 题解
    POJ 1852 Ants
    加强赛第一轮题解
    喵哈哈村的魔法考试 Round #3 (Div.2)
    python小数据池,代码块的最详细、深入剖析
    比较三个数的大小
  • 原文地址:https://www.cnblogs.com/momosmile/p/4641511.html
Copyright © 2011-2022 走看看