zoukankan      html  css  js  c++  java
  • UI基础--UITableView,UITableViewDataSource,UITableViewDelegate的一些属性和方法

    UITableView(继承自UIScrollView)的常用属性

    1、可以用连线的方式设置数据源和代理

    1 self.tableView.dataSource = self;
    2 self.tableView.delegate = self;

    2、设置高度

    1 @property (nonatomic)   CGFloat rowHeight;//行高
    2 @property (nonatomic)   CGFloat sectionHeaderHeight; //组头的高度
    3 @property (nonatomic) CGFloat sectionFooterHeight; //组尾的高度

    3、设置分割线

    1 @property(nonatomic) UITableViewCellSeparatorStyle separatorStyle;//分割线样式
    2 @property(nonatomic,retain) UIColor;//分割线的颜色

    4、设置tableView是否分组(默认在storyboard中已经设置)

    1 @property (nonatomic, readonly) UITableViewStyle;//UITableViewStylePlain,    不分组;UITableViewStyleGrouped   分组

    5、自定义头和尾部

    1 @property(nonatomic,retain) UIView *tableHeaderView;//头部
    2 @property(nonatomic,retain) UIView *tableFooterView;//尾部

    UITableViewDataSource的常用方法:

    1 @required
    2 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;// 每一组有多少行数据
    3 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;// 每一个cell都包含什么内容(image、textLabel、detailTextLabel,还有一个就是附属物)
    4 @optional
    5 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; // 一个tableView有多少组的数据 ,默认是1
    6 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section; - (NSString *)tableView:(UITableView *)tableView //每一组的头标题
    7 //titleForFooterInSection:(NSInteger)section;//每一组的尾标题
    8 - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView; // 返回右侧导航标题(包含的是每组头标题的数组)

    UITableViewDelegate的常用方法:

    1 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;//每组数据中的行高
    2  - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;//每组数据的组头的高度
    3 - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;//每组数据的组尾的高度
    4 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; //每行被选中时的操作

    UITableViewCell的重用:

    cell的性能优化:当cell滑出屏幕(不用之后),把cell对象存储在特定标示的缓存池,当tableView加载下一个数据的时候,从缓存池中取出空闲的cell:

    1 static NSString *reuseIdentifier = @"cell";//设置缓冲池标识
    2 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    3 if (!cell) {
    4 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];//当缓存池里暂时没有空闲的cell时,初始化一个cell
    5 }

     

     

  • 相关阅读:
    031-进阶(日志)
    Django 路由系统
    C++ 面向对象(接口-抽象类)
    C++ 面向对象(多态)
    C++ 面向对象(数据抽象)
    三十、首页列表显示全部问答,完成问答详情页布局
    二十九、制作首页的显示列表
    二十八、发布功能完成
    二十七、登录之后更新导航
    二十六、完成登录功能,用session记住用户名
  • 原文地址:https://www.cnblogs.com/xiaomoge/p/4200140.html
Copyright © 2011-2022 走看看