UITableView官方文档翻译

  • 一个实例UITableView(简单的表格,表视图)是一个用于展示和编辑分层列表信息
  • tableView显示一个列中的项目列表。UITableView是UIScrollView的子类,它允许用户滚动table,虽然UITableView只允许纵向滚动。这些cell构成表的每个条目是UITableViewCell对象;UITableView使用这些对象绘制的表行可见。cell有内容的标题和图像,可以有靠近的右边缘,accessory视图。标准的accessory视图是公开指示或详细公开按钮;前者导致数据层次结构的下一个层次,而后者则会导致选定项目的详细视图。装饰视图也可以是框架控件,如开关和滑块,也可以是自定义的视图。tableView可以进入编辑模式,用户可以插入,删除,排序表中的row。
  • tableView由零个或多个section组成,每一个section都有自己的row。section的索引号在tableView中标识,row的索引号在section中标识。任何section都可以有选择地在前面的一个header,并且可以选择后跟一个footer。
  • tableView有两种style,uitableviewstyleplain和uitableviewstylegrouped。当你创建一个UITableView实例必须指定其的style,这种style是无法改变的。
    在plain style,section的header和footer浮动以上内容如果一个完整的部分是可见的。一个tableView可以有一个index,作为一个bar在table的右边(例如,A ~ Z)。你可以点击一个特定的标签,跳转到目标section。
    tableView的grouped style为所有单元格提供了一个默认的背景颜色和默认背景视图。背景视图为特定section中的所有cell提供可视分组。例如,一个group可以是一个人的名字和标题,另一个group可以是电话,电子邮件帐户等。见grouped table的实例设置应用程序。在grouped style表中不能有一个(右边的)索引。
  • 许多UITableView的方法采取NSIndexPath对象作为参数和返回值。UITableView制定一个类NSIndexPath能够得到代表row的索引和section索引,并从一个给定的row的索引和section索引构建路径(indexPathForRow:inSection: 方法)。特别是在多个section的tableView中,在确定row之前先确定一个section
  • 一个UITableView对象必须有一个对象作为一个DataSource和一个对象作为Delegate;通常这些对象是应用程序的代理或更频繁,一个自定义UITableViewController对象。DataSource必须遵守UITableViewDataSource协议和Delegate必须遵守UITableViewDelegate协议。数据源提供的信息,UITableView需要构建表和管理数据模型时,一个表的行插入,删除或重新排序。代理管理table行的配置和选择,排序,highlighting,accessory视图,和editing操作。
  • 当发送一个: setEditing:animated:消息,(第一个参数是YES),tableView进入编辑模式,展示了编辑或重新排练的控件,根据UITableViewCell的属性:editingStyle,点击插入或者删除控件使dataSource接收: tableView:commitEditingStyle:forRowAtIndexPath:消息,你提交一个删除或者插入: deleteRowsAtIndexPaths:withRowAnimation: or insertRowsAtIndexPaths:withRowAnimation:,适当的,在编辑模式下,如果tableViewCell的属性:showsReorderControl设置为YES,数据源接收: tableView:moveRowAtIndexPath:toIndexPath:消息,数据源可以通过方法:tableView:canMoveRowAtIndexPath:选择性的对cell进行删除排序.
  • tableView的cell可以进行缓存,你可以创建不同于默认cell的自定义UITableViewCell对象,
  • 当你创建一个新的UITableView或分配一个新的dataSource时,重写:layoutSubviews方法使其调用reloadData,reloadData方法清除了tableView的当前状态,包括当前的选择,然而,如果你显示的调用reloadData,它清除了状态和后来直接或间接调用重载layoutSubviews不触发
  • 状态保存: 在iOS6之后,如果对一个tableView的restorationidentifier分配一个属性,它试着保存当前选中的row和第一个可见的row,table的dataSource采用UIDataSourceModelAssociation协议,他提供了一种方法来识别在table中row的位置和和无关row的内容,如果tableView的dataSource采用UIDataSourceModelAssociation协议,当保存状态切换为顶部可见的row和任何选中cell的标示时,将进行dataSource协商,在恢复过程中,dataSource中将会将这些标识符返回的路径索引和重建的顶部可见,重选的cell。如果dataSource没实现UIDataSourceModelAssociation协议,那么滚动条的位置将被保存和恢复到选定的cell,
  • An instance of UITableView (or simply, a table view) is a means for displaying and editing hierarchical lists of information.
  • 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 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.
  • 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.
  • Table views can have one of two styles, UITableViewStylePlain and UITableViewStyleGrouped. When you create a UITableView instance 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.
  • 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.
  • A 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.
  • 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 showsReorderControl property 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:.
  • 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 explains how.
  • 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.
  • 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.

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/index.html#//apple_ref/occ/instp/UITableView/style

个人翻译,不足之处,欢迎☞出

你可能感兴趣的:(翻译,官方文档,UITableVie)