An instance of UITableView (or simply, a table view) is a means for displaying and editing hierarchical lists of information.

一个UITableVIew(简单的来讲,一个表格视图)的实例是展示和编辑分层的信息列表的方法

A table view displays a list of items in a single column. UITableView is a subclass of UIScrollView, which allows users to scroll through the table, although UITableView allows vertical scrolling only. The cells comprising the individual items of the table are UITableViewCell objects;

表格视图在一个单一列中展示项目列表。UITableView是UIScrollView的一个子类,它允许用户滚动表格,但是UITableView只允许垂直方向上的滚动。由独立项组成的单元格是UITableViewCell的对象。

UITableView uses these objects to draw the visible rows of the table. Cells have content—titles and images—and can have, near the right edge, accessory views. Standard accessory views are disclosure indicators or detail disclosure buttons; the former leads to the next level in a data hierarchy and the latter leads to a detailed view of a selected item. Accessory views can also be framework controls, such as switches and sliders, or can be custom views. Table views can enter an editing mode where users can insert, delete, and reorder rows of the table.

UITableView使用这些对象来拖动表格的可视行。单元格是有内容的-标题和图片-也可以有,在右边缘,副视图(就是那种disclosure点击去跳到另一个视图中去)。标准的副视图是展开指示器或者细节展开按钮;前者导向到数据层级结构中的下一级,后者导向到所选项的一个细节视图。副视图也可以是framework controls(框架控制),比如switch(开关)和slider(滑动条),或者也可以是自定义视图。表格视图可以进入一个编辑模式,在该模式下用户可以插入,删除和对表格的行进行排序。

A table view is made up of zero or more sections, each with its own rows. Sections are identified by their index number within the table view, and rows are identified by their index number within a section. Any section can optionally be preceded by a section header, and optionally be followed by a section footer.

表格视图是由零个及以上的部分(section)组成,每个section都有它自己的行。Sections是由它们的表格视图内的索引数字标记的,Row(行)是由它们的Section内的索引数字标记的。任何Section前面可以选择性地有section header(头部),也选择性地有section footer(足部)。

Table views can have one of two styles, UITableViewStylePlain and UITableViewStyleGrouped. When you create a UITableViewinstance you must specify a table style, and this style cannot be changed. In the plain style, section headers and footers float above the content if the part of a complete section is visible. A table view can have an index that appears as a bar on the right hand side of the table (for example, "A" through "Z"). You can touch a particular label to jump to the target section. The grouped style of table view provides a default background color and a default background view for all cells. The background view provides a visual grouping for all cells in a particular section. For example, one group could be a person's name and title, another group for phone numbers that the person uses, and another group for email accounts and so on. See the Settings application for examples of grouped tables. Table views in the grouped style cannot have an index.

表格视图可以有UITableViewStylePlain和UITableViewStyleGrouped两种类型中的一个。当创建了一个UITableView实例的时候,一定要规定表格的类型,类型值是不可以改变的。在plain(无格式)类型中,section header 和 footer 在内容之上漂浮,如果那部分的完成的section是可视的。表格视图可以有以一个在视图右手边以条状显示的索引(比如A到Z 通讯录里面的那种)。你可以点触一个label跳转到目标section。grouped(分组)型的表格视图为所有cells提供了一个默认的背景颜色和一个默认的背景视图。背景视图提供了一个对特定的section所有cell可视的分组。比如说,一个分组可以是一个人的名字和头衔,另一个分组可以是那个人的电话号码,再一个分组可以是邮件账号等等。查看分组表格的设置应用例子。表格应用分组类型中不可以有索引。

Many methods of UITableView take NSIndexPath objects as parameters and return values. UITableView declares a category on NSIndexPath that enables you to get the represented row index (row property) and section index (section property), and to construct an index path from a given row index and section index (indexPathForRow:inSection: method). Especially in table views with multiple sections, you must evaluate the section index before identifying a row by its index number.

UITableView的许多方法使用NSIndexPath对象作为参数和返回值。UITableView在NSIndexPath中声明了一个类(category),来授权你获得显示行索引(row属性)和section索引(section属性),从一个给予的row索引和section索引(indexPathForRow:inSection:方法)构造一个索引路径。尤其是在有多个section的表格视图,一定要在识别一个行row之前校验section索引值。

UITableView object must have an object that acts as a data source and an object that acts as a delegate; typically these objects are either the application delegate or, more frequently, a custom UITableViewController object. The data source must adopt the UITableViewDataSource protocol and the delegate must adopt the UITableViewDelegate protocol. The data source provides information that UITableView needs to construct tables and manages the data model when rows of a table are inserted, deleted, or reordered. The delegate manages table row configuration and selection, row reordering, highlighting, accessory views, and editing operations.

UITableView对象一定有一个作为数据源的对象和一个座位delegate(委托、代表)的对象;典型的是这些对象是应用代表或者,更常见的,一个自定义的UITableViewController对象。数据源一定要采用UITableViewDataSource协议,delegate一定要采用UITableViewDelegate协议。数据源提供了当一个表格被插入、删除或者重新排序时UITableView需要用来构造表格和管理数据的模型。delegate管理表格行的配置和选择,行重排序,强调,副视图和编辑操作。

When sent a setEditing:animated: message (with a first parameter of YES), the table view enters into editing mode where it shows the editing or reordering controls of each visible row, depending on the editingStyle of each associated UITableViewCell. Clicking on the insertion or deletion control causes the data source to receive a tableView:commitEditingStyle:forRowAtIndexPath:message. You commit a deletion or insertion by calling deleteRowsAtIndexPaths:withRowAnimation: or insertRowsAtIndexPaths:withRowAnimation:, as appropriate. Also in editing mode, if a table-view cell has its showsReorderControlproperty set to YES, the data source receives a tableView:moveRowAtIndexPath:toIndexPath: message. The data source can selectively remove the reordering control for cells by implementing tableView:canMoveRowAtIndexPath:.

当发送一个setEditing:animated:信息(第一个参数是YES的情况下),表格视图进入编辑模式,在该模式中显示对每个可视行的编辑或者重新排序操作,这取决于分配给每个UITableViewCell的editingStyle(编辑形式)值,点击插入或者删除控制会使数据源接受一个tableView:commitEditingStyle:forRowAtIndexPath:信息。你可以适时通过调用deleteRowsAtIndexPaths:withRowAnimation:或者 insertRowsAtIndexPaths:withRowAnimation:提交删除或者插入请求。同样地,在编辑模式中,如果一个表格视图的单元格的showsReorderControl属性被设为YES,数据源接受一个tableView:moveRowAtIndexPath:toIdnexPath:信息。数据源通过实现tableView:canMoveRowAtIndexPath:方法对单元格可以选择移除或者重新排序操作

UITableView caches table-view cells for visible rows. You can create custom UITableViewCell objects with content or behavioral characteristics that are different than the default cells; "A Closer Look at Table View Cells in Table View Programming Guide for iOS" in Table View Programming Guide for iOS explains how.

UITableView为可视的行缓存表格视图的单元格。可以用内容(content)或者行为特征创建与默认的单元格不同的自定义的UITableViewCell对象;Table View Programming Guide for iOSiOS表格视图编程指导中的"A Closer Look at Table View Cells in Table View Programming Guide for iOS"解释了如何去操作。

UITableView overrides the layoutSubviews method of UIView so that it calls reloadData only when you create a new instance of UITableView or when you assign a new data source. Reloading the table view clears current state, including the current selection. However, if you explicitly call reloadData, it clears this state and any subsequent direct or indirect call to layoutSubviews does not trigger a reload.

UITableView 重载了UIView的layoutSubviews方法所以它仅调用reloadData(重载数据)当你创建了一个新的UITableView实例活着当你分配了新的数据源。重载表格视图清除了当前的状态,包括当前的选择。但是,如果明确地调用了reloadData,它清除了这个状态和任何其他随后的直接或者间接对layoutSubviews调用就不会触发一次重新载入。

State Preservation

In iOS 6 and later, if you assign a value to a table view’s restorationIdentifier property, it attempts to preserve the currently selected rows and the first visible row. The table’s data source may adopt the UIDataSourceModelAssociation protocol, which provides a way to identify a row’s contents independent of that row’s position in the table. If the table’s data source adopts the UIDataSourceModelAssociation protocol, the data source will be consulted when saving state to convert the index paths for the top visible row and any selected cells to identifiers. During restoration, the data source will be consulted to convert those identifiers back to index paths and reestablish the top visible row, and reselect the cells. If the table’s data source does not implement the UIDataSourceModelAssociation protocol, the scroll position will be saved and restored directly, as will the index paths for selected cells.

在iOS6或之后,如果你给表格视图的restorationIndentifier属性分配了一个值的话,它会尝试去保护当前选中的行和视图的第一可视行。表格的数据源可能采用UIDataSourceModelAssociation协议,它提供了一种去识别一个行的内容之于行在这个表格中的位置的独立性的方法。如果表格的数据源采用UIDataSourceModelAssociation协议,当保存状态来转换顶部可视行和其他任何单元格的索引路径为标签时,数据源将会被询问。在恢复期间,数据源将会被询问来转换这些标签回索引路径然后重新建立顶部可视行,再重新选择单元格。如果表格的数据源没有实现UIDataSourceModelAssocaition协议,滚动位置将会被保存和直接恢复为所选单元格的索引路径。

For more information about how state preservation and restoration works, see App Programming Guide for iOS.

For more information about appearance and behavior configuration, see Table Views in UIKit User Interface Catalog.

Initializing a UITableView Object

  • Initializes and returns a table view object having the given frame and style.

    Declaration

    SWIFT

    init(frame frame: CGRect,
         style style: UITableViewStyle)

    OBJECTIVE-C

    - (instancetype)initWithFrame:(CGRect)frame
                            style:(UITableViewStyle)style

    Parameters

    frame

    A rectangle specifying the initial location and size of the table view in its superview's coordinates. The frame of the table view changes as table cells are added and deleted.

    style

    A constant that specifies the style of the table view. See Table View Style for descriptions of valid constants.

    Return Value

    Returns an initialized UITableView object or nil if the object could not be successfully initialized.

    Discussion

    You must specify the style of a table view when you create it and you cannot thereafter modify the style. If you initialize the table view with the UIView method initWithFrame:, the UITableViewStylePlain style is used as a default.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

转载于:https://www.cnblogs.com/baaingSheep/p/4278655.html

[UITableView]简介相关推荐

  1. IOS UITableView详解一数据展示 页面简单实现

    为什么80%的码农都做不了架构师?>>>    一 UITableView简介 UITableView用于表格数据展示,是使用频率最高的控件.UITableView继承自UIScro ...

  2. UITableView学习笔记

    2019独角兽企业重金招聘Python工程师标准>>> http://www.cnblogs.com/smileEvday/archive/2012/06/28/tableView. ...

  3. iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)

    iOS开发UI篇-使用UItableview完成一个简单的QQ好友列表(一) 一.项目结构和plist文件 二.实现代码 1.说明: 主控制器直接继承UITableViewController // ...

  4. UITableView 学习笔记

    http://www.cnblogs.com/smileEvday/archive/2012/06/28/tableView.html UITableView学习笔记 作者:一片枫叶 看TableVi ...

  5. UITableView 详解 教程

    看TableView的资料其实已经蛮久了,一直想写点儿东西,却总是因为各种原因拖延,今天晚上有时间静下心来记录一些最近学习的TableView的知识.下面进入正题,UITableView堪称UIKit ...

  6. UITableView知识梳理须知—(一)

    1.UITableView掌握 1>  设置UITableView的dataSource.delegate 2>    UITableView多组数据和单组数据的展示 3>  UIT ...

  7. qt tableview修改表格内容_如何修改一次代码就可以完成多种类型 cell 的 UITableView 增删修改

    前言 当一个 tableView 中的 cell 类型过多时,我们务必会在 tableView 的各个代理中做这样那样的判断,当需要增加一种 cell,或调换 cell 的顺序的时候我们就会在 tab ...

  8. iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(二)

    一.实现效果             二.实现代码 1.数据模型部分 YYQQGroupModel.h文件 1 // 2 // YYQQGroupModel.h 3 // 02-QQ好友列表(基本数据 ...

  9. etcd 笔记(01)— etcd 简介、特点、应用场景、常用术语、分布式 CAP 理论、分布式原理

    1. etcd 简介 etcd 官网定义: A highly-available key value store for shared configuration and service discov ...

  10. Docker学习(一)-----Docker简介与安装

    一.Docker介绍 1.1什么是docker Docker是一个开源的应用容器引擎,基于Go语言并遵从Apache2.0协议开源 Docker可以让开发者打包他们的应用以及依赖包到一个轻量级,可移植 ...

最新文章

  1. 【图像分类案例】(2) DenseNet 天气图片四分类(权重迁移学习),附Tensorflow完整代码
  2. 63.不同的路径II
  3. Qt CheckBox的使用
  4. java重载与重写的区别你懂了吗
  5. JavaScript实现longestCommonSubsequence最长公共子序列算法(附完整源码)
  6. 89. Gray Code - LeetCode
  7. 芯片破壁者:硅谷“摩西”肖克利和他的半导体实验室
  8. 19 Tips For Everyday Git Use
  9. 如何提升应用程序启动权限
  10. python爬虫什么意思-网络爬虫是什么(python爬虫有什么用)
  11. shell脚本中执行命令_如何在Shell脚本中执行命令?
  12. Arturia Pigments Mac:模拟振荡器和波表振荡器的结合
  13. 9.数据结构 --- 查找
  14. c语言中dist有是什么作用,C语言习题及答案(第九章).doc
  15. 上计算机课没有签到肿么办,钉钉教学直播如何课前签到 钉钉直播如何提醒未签到的学生...
  16. 【一键新机】免root/不刷机/拒绝Xposed 实现 Android改机,全新技术分析。
  17. UCenter+云市场?开源用户中心2.0时代即将开启
  18. 脚本工作室对游戏的危害
  19. 曾推出Anki Drive和Cozmo人工智能机器人的独角兽企业Anki谢幕
  20. MP中的条件更新操作

热门文章

  1. 【追一科技】AAAI、ACL、EMNLP等顶会论文成果分享
  2. 让AI捕捉“七情”,多模态情感分析的应用和挑战
  3. ERICA: 提升预训练语言模型实体与关系理解的统一框架
  4. 邱锡鹏:为什么相比于CV,NLP领域的发展要缓慢?
  5. 算法同学从学校到实习,需要改变什么
  6. 干货 | 深度文本分类综述(12篇经典论文)
  7. 十分钟弄懂字节对编码
  8. TensorFlow学习笔记——自然语言处理
  9. 正则表达式:re.match、re.search、re.sub、re.compile、findall、re.finditer、re.split
  10. sql增删改查_5分钟GET全栈开发 - 增删改查的取经之路