Table View Programming Guide for iOS---(三)----Overview of the Table View API
Overview of the Table View API
表格视图API概述
The table view programming interface includes several UIKit classes, two formal protocols, and a category added to a Foundation framework class.
表格视图编程接口包括好几个UIKit类,两个正式的协议以及添加到Foundation 框架类的一个类别(category)。
Table View
一、表格视图
A table view itself is an instance of the UITableView
class. You use its methods to configure the appearance of the table view—for example, specifying the default height of rows or providing a subview used as the header for the table. Other methods give you access to the currently selected row as well as specific rows or cells. You can call other methods of UITableView
to manage selections, scroll the table view, and insert or delete rows and sections.
表格视图是UITableView类的一个实例。你使用它的方法来配置表格视图的外形--比如,指定行的默认高度或提供一个子视图作为表格的表头。其它方法让你访问当前被选中的行以及特定行或单元格。你可以调用UITableView类的其它方法来管理选择(selections),管理表格视图,以及插入或删除行和区(sections)。
UITableView
inherits from the UIScrollView
class, which defines scrolling behavior for views with content larger than the size of the window. UITableView
redefines the scrolling behavior to allow vertical scrolling only.
UITableView是UIScrollView类的子类,滚动视图定义了视图的滚动行为,当视图内容比窗口尺寸大时,可以滚动视图。UITableView 重新定义了滚动行为,它让视图只能纵向滚动。
Table View Controller
二、表格视图控制器
The UITableViewController
class manages a table view and adds support for many standard table-related behaviors such as selection management, row editing, table configuration, and others. This additional support is there to minimize the amount of code you have to write to create and initialize your table-based interface. You don’t use this class directly—instead you subclass UITableViewController
to add custom behaviors.
UITableViewController 类管理一个表格视图以及添加支持了很多跟表格相关的标准行为,比如选择管理,行编辑,表格配置,等等。 这种额外的支持减少了你必须编写用来创建和初始化基于表格的接口的代码总量。你不会直接使用该类---相反,你需要子类化UITableViewController 来添加自定义行为。
Data Source and Delegate
三、数据源和委托
A UITableView
object must have a delegate and a data source. Following the Model-View-Controller design pattern, the data source mediates between the app’s data model (that is, its model objects) and the table view. The delegate, on the other hand, manages the appearance and behavior of the table view. The data source and the delegate are often (but not necessarily) the same object, and that object is usually a custom subclass of UITableViewController
. (See“Navigating a Data Hierarchy with Table Views” for further information.)
UITableView对象必须有一个委托和一个数据源。 遵循模型-视图-控制器 设计模式,数据源就是应用程序数据模型(模型对象)和表格视图之间的媒介。 另一方面,委托管理表格视图的外形和行为。数据源和委托常常(但不一定)是同一个对象,并且该对象通常是UITableViewController 的一个子类。 (参见“Navigating a Data Hierarchy with Table Views” 了解进一步的信息.)
The data source adopts the UITableViewDataSource
protocol. UITableViewDataSource
has two required methods. The tableView:numberOfRowsInSection:
method tells the table view how many rows to display in each section, and the tableView:cellForRowAtIndexPath:
method provides the cell to display for each row in the table. Optional methods allow the data source to configure multiple sections, provide headers and/or footers, and support adding, removing, and reordering rows in the table.
数据源采用了UITableViewDataSource 协议。UITableViewDataSource 有两个必须的方法。方法 tableView:numberOfRowsInSection: 告诉表格视图每个区里有多少行,
以及方法 tableView:cellForRowAtIndexPath: 提供了表格中每行显示的单元格。可选方法让数据源配置多个区,提供表头和/或表尾,以及支持添加,删除,和在表格中重新排序行。
The delegate adopts the UITableViewDelegate
protocol. This protocol has no required methods. It declares methods that allow the delegate to modify visible aspects of the table view, manage selections, support an accessory view, and support editing of individual rows in a table.
委托采用了 UITableViewDelegate 协议。该协议没有必须方法。它声明了允许委托修改表格视图可见内容的各种方法,管理选择项,支持一个辅助视图,以及在表中支持编辑单独行。
An app can make use of the convenience class UILocalizedIndexedCollation
to help the data source organize the data for indexed lists and display the proper section when users tap an item in the index. TheUILocalizedIndexedCollation
class also localizes section titles.
应用程序可以利用方便类UILocalizedIndexedCollation 来帮助数据源为索引列表组织数据,并在当用户点击索引里的一个数据项时显示正确的区。
Extension to the NSIndexPath Class
四、扩展NSIndexPath类
Many table view methods use index paths as parameters or return values. An index path identifies a path to a specific node in a tree of nested arrays, and in the Foundation framework it is represented by an NSIndexPath
object. UIKit declares a category on NSIndexPath
with methods that return key paths, locate rows in sections, and constructNSIndexPath
objects from row and section indexes. For more information, see NSIndexPath UIKit Additions.
很多表格视图使用索引路径作为参数或返回值。索引路径在嵌套数组树中标识一个路径到一个特定的节点,在Foundation 框架中它由一个NSIndexPath 对象表示。UIKit为NSIndexPath声明了一个类别,以及返回关键路径,在区中定位行,以及用行和区索引结构建NSIndexPath 对象的各种方法,更多信息,请看NSIndexPath UIKit Additions.
Table View Cells
五、表格视图单元格
As noted in “Data Source and Delegate,” the data source must return a cell object for each visible row that a table view displays. These cell objects must inherit from the UITableViewCell
class. This class includes methods for managing cell selection and editing, managing accessory views, and configuring the cell. You can instantiate cells directly in the standard styles defined by the UITableViewCell
class and give these cells content consisting of one or two strings of text and, in some styles, both image and text. Instead of using a cell in a standard style, you can put your own custom subviews in the content view of an “off-the-shelf” cell object. You may also subclass UITableViewCell
to customize the appearance and behavior of table view cells. These approaches are all discussed in “A Closer Look at Table View Cells.”
正如“Data Source and Delegate,” 里所讲, 数据源必须为表格视图显示的每个可见行返回一个单元格对象。这些单元格对象必须继承自UITableViewCell 类。 该类包含了管理单元格选项以及编辑,管理辅助视图,和配置单元格的各种方法。你可以从UITableViewCell 类定义的标准风格中直接实例化单元格,然后给这些单元格提供由一个或两个字符串文件组成的内容,或者一些风格中,由图片和文本组成。你可以在一个现成的单元格对象的内容视图里放置你自己定义子视图,而不使用一个标准风格的单元格。你也可以子类化UITableViewCell类来自定义表格视图单元格的外形和行为。这些实现都在“A Closer Look at Table View Cells.” 里有讨论。
Table View Programming Guide for iOS---(三)----Overview of the Table View API的更多相关文章
- View Programming Guide for iOS ---- iOS 视图编程指南(五)---Animations
Animations Animations provide fluid visual transitions between different states of your user inter ...
- View Programming Guide for iOS ---- iOS 视图编程指南(四)---Views
Views Because view objects are the main way your application interacts with the user, they have many ...
- 【IOS笔记】View Programming Guide for iOS -1
原文:View Programming Guide for iOS View and Window Architecture Views and windows present your applic ...
- View Programming Guide for iOS ---- iOS 视图编程指南(二)---View and Window Architecture
View and Window Architecture 视图和窗口架构 Views and windows present your application’s user interface and ...
- View Programming Guide for iOS ---- iOS 视图编程指南(一)
Next About Windows and Views 关于窗口和视图 In iOS, you use windows and views to present your application’s ...
- View Programming Guide for iOS ---- iOS 视图编程指南(三)---Windows
Windows Every iOS application needs at least one window—an instance of the UIWindow class—and some m ...
- Table View Programming Guide for iOS---(五)---Creating and Configuring a Table View
Creating and Configuring a Table View Your app must present a table view to users before it can mana ...
- Table View Programming Guide for iOS---(六)---A Closer Look at Table View Cells
A Closer Look at Table View Cells A table view uses cell objects to draw its visible rows and then c ...
- 《View Programming Guide for iOS》之frame、bounds和center之间的关系
The frame property contains the frame rectangle, which specifies the size and location of the view i ...
- 《view programming guide for iOS 》之可以使用动画效果的属性
frame—Use this to animate position and size changes for the view. ,框架,可以视图动态改变大小和位置 bounds—Use this ...
随机推荐
- Oracle版本–EBS R12.1.1
select * from v$version; Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Productio ...
- BUPT复试专题—奇偶求和(2014软件)
题目描述 给出N个数,求出这N个数,奇数的和以及偶数的和. 输入 第一行为测试数据的组数T(1<=T<=50).请注意,任意两组测试数据之间是相互独立的. 每组数据包括两行: 第一行为一个 ...
- nrf51822中app_button 的应用
Button Handler(按键处理程序) 按键处理程序是使用GPIOTE(GPIO Task and Event)的处理机制实现的,为了防止按键的抖动.在GPIOTE event(事件)处理程序中 ...
- HTML页面底部无用留白
HTML页面底部无用留白,可以再footer样式中加入: overflow: hidden; 如有错误,请您指正~
- 线程池实例:使用Executors和ThreadPoolExecutor
线程池负责管理工作线程,包含一个等待执行的任务队列.线程池的任务队列是一个Runnable集合,工作线程负责从任务队列中取出并执行Runnable对象. java.util.concurrent.ex ...
- Arcgis Engine(ae)接口详解(5):IGeometry几何高级操作
IPoint point = new PointClass(); point.PutCoords(, ); //ITopologicalOperator接口用于几何对象的几何操作 ITopologic ...
- Testng 运行报错:"Total tests run: 0, Failures: 0, Skips: 0"以及找不到class文件的问题
"Total tests run: 0, Failures: 0, Skips: 0" This means that there were no tests executed a ...
- jvm 调优(1)概念
数据类型 Java虚拟机中,数据类型可以分为两类:基本类型和引用类型.基本类型的变量保存原始值,即:他代表的值就是数值本身:而引用类型的变量保存引用值.“引用值”代表了某个对象的引用,而不是对象本身, ...
- 前端遇上Go: 静态资源增量更新的新实践
前端遇上Go: 静态资源增量更新的新实践https://mp.weixin.qq.com/s/hCqQW1F8FngPPGZAisAWUg 前端遇上Go: 静态资源增量更新的新实践 原创: 洋河 美团 ...
- HDFS集群安装部署
准备环境: 三台centos7虚拟机(Node-1,Node-2,Node-3) 配置虚拟机网络,保证三台机器可以互相ping通,并且和宿主机可以互相ping通.如果仅仅是作为虚拟机学习,可以关闭防火 ...