知识点:

1)UITableView

2)UITableViewCell

======================================================

一、UITableView

1、UITableView介绍

UITableView为列表视图,继承UIScrollView

2、常用的属性

1)separatorColor  分割线颜色

2)separatorStyle  分割线样式

3)separatorInset 分割线的位置

3)rowHeight  cell的高度,默认为44

4)dataSource  数据源代理

5)delegate  代理

3、复用机制

4、常用代理

//设置组的数目

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

//设置每组的cell数目

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

//设置cell的内容

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

//设置cell的高度

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

//当点击cell时会自动调动

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

=====================================================

二、UITableViewCell

1、UITableViewCell介绍

UITableView上每一行就是一个UITableViewCell,用来显示不同的内容

2、cell的样式

1⃣️. UITableViewCellStyleDefault, // 只有一个label(即textLabel正标题)在右边,和imageView在左边

2⃣️. UITableViewCellStyleValue1, // 两个label,左边的label(即textLabel正标题)字体默认为黑色并 且向左对齐,右边的label字体(即detailTextLabel副标题)默认为黑色并且向右对齐

3⃣️. UITableViewCellStyleValue2, //两个label,左边的label(即textLabel正标题)字体默认为蓝色并 且向右对齐,右边的label字体(即detailTextLabel副标题)默认为黑色并且向左对齐

4⃣️.  UITableViewCellStyleSubtitle // Left aligned label on top and left aligned label on bottom with gray text (Used in iPod).上下两个label,上边的label(即textLabel正标题)字体默认为灰色并且向左对 齐,下边的label字体(即detailTextLabel副标题)默认为灰色并且向左对齐

3、UITableViewCell属性(使用cell中的系统控件时,要注意cell的样式,倘若没有,就算写了也不会显示)

1)textLabel   标题

2)detailTextLabel  副标题

3)imageView

4)accessoryType  右边的图片样式(默认是UITableViewCellAccessoryNone)设置了样式才会显示

  /**

UITableViewCellAccessoryNone 没有样式(默认值)

UITableViewCellAccessoryDisclosureIndicator 箭头

UITableViewCellAccessoryDetailDisclosureButton 感叹号和箭头

UITableViewCellAccessoryCheckmark 打钩

UITableViewCellAccessoryDetailButton 感叹号

*/

5)selectionStyle  点击cell时高亮效果,具体样式如下

  /**

UITableViewCellSelectionStyleNone 无

UITableViewCellSelectionStyleDefault 默认,灰色

*/

6)cell的操作

删除cell

- (void)deleteRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;

添加cell

- (void)insertRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;

移动cell

- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath

刷新

- (void)reloadRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation

4、组头和表头区别

1⃣️.组头或者组尾的显示需要代理的实现

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

// 设置组头或者组尾的高度才会调用viewForHeaderInSection或者viewForFooterInSection代理

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

2⃣️.UITableViewHeaderFooterView属性

1)textLabel   标题

2)detailTextLabel  副标题

3⃣️.表头(tableHeaderView),表头只有一个,高度由当前创建的view决定,宽度由tableView决定

5、tableView其他常用代理

1)返回组头的标题

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

2)返回组尾的标题

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;

3)  是否允许编辑,默认全部允许编辑

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

4)修改删除按钮上的文字

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath

5)编辑状态,实现这个代理就可以删除或插入(通过判断editingStyle的类型,做出相应的操作)

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

6)  // 8.0 的新代理方法

// 同时设置左划cell时出现多个按钮(删除、置顶、更多)

// 如果实现了这个代理方法,自带的删除就没有了

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

//通过以下方法创建按钮

+ (instancetype)rowActionWithStyle:(UITableViewRowActionStyle)style title:(nullable NSString *)title handler:(void (^)(UITableViewRowAction *action, NSIndexPath *indexPath))handler;

7)移动cell的代理,实现了这个代理才能移动

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

8)返回索引

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

【备注】UITableViewIndexSearch 搜索的图标

9)控制索引

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index

【备注】返回-1,什么都不做

UITableView的更多相关文章

  1. iOS UITableView 与 UITableViewController

    很多应用都会在界面中使用某种列表控件:用户可以选中.删除或重新排列列表中的项目.这些控件其实都是UITableView 对象,可以用来显示一组对象,例如,用户地址薄中的一组人名.项目地址. UITab ...

  2. UITableView(二)

    #import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...

  3. iOS: 在UIViewController 中添加Static UITableView

    如果你直接在 UIViewController 中加入一个 UITableView 并将其 Content 属性设置为 Static Cells,此时 Xcode 会报错: Static table ...

  4. iOS 编辑UITableView(根据iOS编程编写)

    上个项目我们完成了 JXHomepwner 简单的应用展示,项目地址.本节我们需要在上节项目基础上,增加一些响应用户操作.包括添加,删除和移动表格. 编辑模式 UITableView 有一个名为  e ...

  5. 使用Autolayout实现UITableView的Cell动态布局和高度动态改变

    本文翻译自:stackoverflow 有人在stackoverflow上问了一个问题: 1 如何在UITableViewCell中使用Autolayout来实现Cell的内容和子视图自动计算行高,并 ...

  6. iOS - UITableView中Cell重用机制导致Cell内容出错的解决办法

    "UITableView" iOS开发中重量级的控件之一;在日常开发中我们大多数会选择自定Cell来满足自己开发中的需求, 但是有些时候Cell也是可以不自定义的(比如某一个简单的 ...

  7. UITableView cell复用出错问题 页面滑动卡顿问题 & 各杂七杂八问题

    UITableView 的cell 复用机制节省了内存,但是有时对于多变的自定义cell,重用时会出现界面出错(例如复用出错,出现cell混乱重影).滑动卡顿等问题,这里只简单敲下几点复用出错时的解决 ...

  8. UITableview delegate dataSource调用探究

    UITableview是大家常用的UIKit组件之一,使用中我们最常遇到的就是对delegate和dataSource这两个委托的使用.我们大多数人可能知道当reloadData这个方法被调用时,de ...

  9. UITableView点击每个Cell,Cell的子内容的收放

    关于点击TableviewCell的子内容收放问题,拿到它的第一个思路就是, 方法一: 运用UITableview本身的代理来处理相应的展开收起: 1.代理:- (void)tableView:(UI ...

  10. 使用UITableView的分组样式

    分组样式顾名思义是对TableView中的数据行进行分组处理,每个分组都有一个header和footer. TableView中header的英文文本是大写的,footer的英文文本是小写的.如下图浅 ...

随机推荐

  1. 在这个变化的年代,IT人的方向在哪里?看两个故事

    王超是我的朋友,来京四年整.最初在一家民企做LINUX运维工程师,月薪5000.工作很认真,埋头苦干型,每天工作时间很长,让加班从来无怨言.即使是周末休假,只要有工作任务也是随叫随到.然而当他提涨薪时 ...

  2. 手机端web学习基础--from慕课网

    web知识零零散散的知道一些,但总感觉不够系统,遇到问题不知道如何解决,因此特此来系统的学习一下web前端的知识.从慕课网的web基础看起.下面学习http://www.imooc.com/learn ...

  3. 前端自动化开发之grunt

    上篇文章介绍了前端模块化开发工具seaJs,利用seaJs我们可以轻松实现前端的模块化编程,参见http://www.cnblogs.com/luozhihao/p/4818782.html 那么今天 ...

  4. 当前标识(IIS APPPOOL\dfcreport)没有对“C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files”的写访问权限。

    Asp.NET网站部署到IIS上面,浏览出现如下图所示错误. 原因原因最 原因: 1.IIS对该文件夹没有写的权限. 2.IIS和asp.net安装顺序错误,应该先IIS,然后asp.net. 3.没 ...

  5. Web API配置自定义路由

    默认访问Web API时,是无需指定method名.它会按照默认的路由来访问.如果你的Web API中出现有方法重载时,也许得配置自定义路由: 标记1为自定义路由,标记2为默认路由,需要把自定义路由排 ...

  6. c# TCP Socket通讯基础

    在做网络通讯方面的程序时,必不可少的是Socket通讯. 那么我们需要有一套既定的,简易的通讯流程. 如下: <pre name="code" class="csh ...

  7. 介绍开源的.net通信框架NetworkComms框架 源码分析(六)SendReceiveOptions

    原文网址: http://www.cnblogs.com/csdev Networkcomms 是一款C# 语言编写的TCP/UDP通信框架  作者是英国人  以前是收费的 目前作者已经开源  许可是 ...

  8. html5学习笔记5--API Range对象(二)

    Range对象之cloneRange和cloneContents 代码效果如下 首次点击“选择内容“按钮提示如下 接着会显示 最后显示 以下为整个代码 <!DOCTYPE html> &l ...

  9. .NET 中获取调用方法名

    在写记录日志功能时,需要记录日志调用方所在的模块名.命名空间名.类名以及方法名,想到使用的是反射(涉及到反射请注意性能),但具体是哪一块儿还不了解,于是搜索,整理如下: 需要添加相应的命名空间: us ...

  10. Android获取系统时间方法的总结

    Android获取系统时间方法的方法有很多种,常用的有Calendar.Date.currentTimeMills等方法. (1)Calendar Calendar获取系统时间首先要用Calendar ...