UITableView是集成UIScrollView的可以实现滚动查看内容

1.1 UITableView的基本方法和属性

  选中的行号

- (NSIndexPath *)indexPathForSelectedRow;                                                // returns nil or index path representing section and row of selection.

 表格编辑模式设置

// Editing. When set, rows show insert/delete/reorder controls based on data source queries@property (nonatomic, getter=isEditing) BOOL editing;                             // default is NO. setting is not animated.
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;

 表格cell的分割线设置,但是一般不符合我们的要求

@property (nonatomic) UITableViewCellSeparatorStyle separatorStyle; // default is UITableViewCellSeparatorStyleSingleLine

1.2 UITableDataSource的基本方法和属性

  表格显示数据的三个方法

@required- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;@optional- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;              // Default is 1 if not implemented

  显示表格组标题

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;    // fixed font style. use custom view (UILabel) if you want something different
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;

  表格组标题索引

// Index- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;                                                    // return list of section titles to display in section index view (e.g. "ABCD...Z#")
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;  // tell table which section corresponds to section title/index (e.g. "B",1))

  表格自带的删除、添加,详细见UITableViewCell的滑动删除随笔

// Data manipulation - insert and delete support// After a row has the minus or plus button invoked (based on the UITableViewCellEditingStyle for the cell), the dataSource must commit the change
// Not called for edit actions using UITableViewRowAction - the action's handler will be invoked instead
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;

1.3 UITableViewDelegate方法

  实现自定义组头和组尾视图,需实现下面2个方法,返回的UIView为自定义View并需要继承UITableViewHeaderFooterView

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;   // custom view for header. will be adjusted to default or specified header height
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;   // custom view for footer. will be adjusted to default or specified footer height

  设置行高,组高

// Variable height support- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

  行选中方法

// Selection// -tableView:shouldHighlightRowAtIndexPath: is called when a touch comes down on a row.
// Returning NO to that message halts the selection process and does not cause the currently selected row to lose its selected look while the touch is down.
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0);
- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0);
- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0);// Called before the user changes the selection. Return a new indexPath, or nil, to change the proposed selection.
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0);
// Called after the user changes the selection.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0);

 行编辑

// Editing// Allows customization of the editingStyle for a particular cell located at 'indexPath'. If not implemented, all editable cells will have UITableViewCellEditingStyleDelete set for them when the table has editing property set to YES.
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0);
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(8_0); // supercedes -tableView:titleForDeleteConfirmationButtonForRowAtIndexPath: if return value is non-nil// Controls whether the background is indented while editing.  If not implemented, the default is YES.  This is unrelated to the indentation level below.  This method only applies to grouped style table views.
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath;// The willBegin/didEnd methods are called whenever the 'editing' property is automatically changed by the table (allowing insert/delete/move). This is done by a swipe activating a single row
- (void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath;

转载于:https://www.cnblogs.com/HJiang/p/4196915.html

UITableView UITableDataSource UITableViewDelegate的基本方法和属性相关推荐

  1. 技术图文:Python魔法方法之属性访问详解

    背景 今天在B站学习"零基础入门学习 Python"中的第45节"魔法方法:属性访问",这也是我们组织的 Python基础刻意练习活动 的学习任务,其中有这样的 ...

  2. 一个用户实体应该有它自己的实体验证,即一个实体应该有它的属性,方法,扩展属性及验证机制组成...

    一个存储验证信息的公用类: /// <summary>      /// 验证信息实体类      /// </summary>      public class RuleV ...

  3. python中文读音ndarray-numpy中的ndarray方法和属性详解

    NumPy数组的维数称为秩(rank),一维数组的秩为1,二维数组的秩为2,以此类推.在NumPy中,每一个线性的数组称为是一个轴(axes),秩其实是描述轴的数量.比如说,二维数组相当于是一个一维数 ...

  4. JS-DOM Element方法和属性

    JS-DOM Element方法和属性 S-DOM Element方法和属性 一,获取html元素 1.getElementByID(id) 通过对元素的ID访问,这是DOM一个基础的访问页面元素的方 ...

  5. 自动装配——@Autowired 构造器,参数,方法,属性都是从容器中获取参数组件的值||自定义组件想要使用Spring容器底层的一些组件 ApplicationContext,BeanFactory

    @Autowired:构造器,参数,方法,属性:都是从容器中获取参数组件的值 * 1).[标注在方法位置]:@Bean+方法参数:参数从容器中获取;默认不写@Autowired效果是一样的:都能自动装 ...

  6. python 使用dir() help() 查看一个对象所有拥有的方法和属性

    可以使用python 的内置方法 dir() 或者help() 查看 某个对象所拥有的方法和属性, 二者间的区别是: dir() : 只是得到方法或者属性的名称 help():不但可以得到对象的方法和 ...

  7. Python 内置方法和属性应用:反射和单例

    1. 前言 python除了丰富的第三方库外,本身也提供了一些内在的方法和底层的一些属性,大家比较常用的如dict.list.set.min.max.range.sorted等.笔者最近在做项目框架时 ...

  8. python内置类属性_Python内置方法和属性应用:反射和单例(推荐)

    1. 前言 python除了丰富的第三方库外,本身也提供了一些内在的方法和底层的一些属性,大家比较常用的如dict.list.set.min.max.range.sorted等.笔者最近在做项目框架时 ...

  9. ViewController类中得方法和属性的用途

    ViewController类中得方法和属性的用途 1. wantsFullScreenLayout 只要在UIViewController上设置wantsFullScreenLayout=true ...

最新文章

  1. 远程办公中的IT女性:工作量增加3倍,离职率却下降近50%
  2. FastDFS安装、配置、部署(三)-Storage配置具体解释
  3. sd卡linux错误检测,android系统正在准备SD卡正在检测是否有错误且SD卡无法读取解决办法...
  4. 京东下拉词框推广是什么?
  5. 【真的很先进】阿里云在2018-KVM Forum上分享的动态迁移实践
  6. 鸿蒙和想象部落哪个好些,还是想说说鸿蒙
  7. 数据可视化技术:python数据可视化工具库汇总(共21个)
  8. 公有云、私有云、私有化_私有云的未来是什么?
  9. 马克思贡献了预备导数概念
  10. 2019暑假牛客训练赛(补题及笔记)
  11. AndrewNG机器学习听课笔记(1 )——线性回归(linear regression)
  12. 用遗传算法解决VRP问题
  13. C++游戏——小胎大乱斗
  14. php获取小米手环数据,小米运动App数据提取
  15. JAVA-win7的JDK环境变量配置安装
  16. TM4C KEIL模板建立
  17. thinkphp5oa管理系统
  18. 文件操作之不得不知的细节
  19. Linux使用Android的USB共享网络
  20. 微软使用郑码输入法10年未付费遭起诉

热门文章

  1. ds18b20温度转换指令_【Proteus】DS18B20简易温控器
  2. 新建/初始化git仓库
  3. while循环里面scanf_5.1 for循环
  4. python 任务调度 celery_python任务调度模块celery(二)
  5. python中return返回值为函数名_Python函数返回值
  6. Flink分布式standalone部署方式(第二种方式)
  7. Python视频制作工具Manim入门,文本使用详细介绍
  8. 实用脚本!利用 Python 对 PDF 进行加密、解密操作,代码拿走就用!
  9. 真香!一行Python代码,帮你制作小姐姐的表情包,靠谱吗?
  10. 豆瓣读书评分 8.7 以上! 这 40 本 Python 畅销书包邮送