【iOS】Table View Programming Guide for iOS

table view分为两种:plain 和 grouped

Plain Table Views

A table view configured as an indexed list

A table view configured as a selection list

Grouped Table Views

A table view in the grouped style

Header and footer of a section

Standard Styles for Table View Cells

Style Demo
UITableViewCellStyleDefault
UITableViewCellStyleSubtitle
UITableViewCellStyleValue1
UITableViewCellStyleValue2

Overview of the Table View API

Table View

UITableView 继承自 UIScrollView,但是重新定义了 scrolling behavior ,只允许竖直方向的滚动。

Data Source and Delegate

UITableViewDataSource有两个required methods,tableView:numberOfRowsInSection:tableView:cellForRowAtIndexPath:UITableViewDelegate 协议就没有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.

Navigating a Data Hierarchy with Table Views

可以使用initWithStyle:方法来创建一个table view,传递参数 UITableViewStylePlainUITableViewStyleGrouped

尽量使用UIViewController的子类,而不要直接只用UITableViewController,因为UITableViewController会直接创建一个全屏的table view,如果只是想把table view作为一部分使用,就不好处理了,所以用UIViewController自定义table view 的大小,自由度更高。

Managing Table Views in a Navigation-Based App

当用户点击table view 的某一行时,table view 调用了 tableView:didSelectRowAtIndexPath: 或者 tableView:accessoryButtonTappedForRowWithIndexPath: 方法,都是由delegate实现的。后一个方法是当用户点击某一行的detail disclosure button时被调用的。