Reprinted from http://blog.csdn.net/y041039/article/details/7351982
I. Overview
UITableView is one of the most important control classes for iOS development. It can be said that anyone doing iOS development must be proficient in using and mastering it. This article is mainly about providing a guide to learning how to use TableView.
To say that UITableView must introduce his several relatives: Uitableviewdelegate,uitableviewdatasource,uitableviewcell. The first two are TableView two protocol (don't tell me you don't know what it's called Protocol OH). This article then lists some of the most important points of knowledge that tableview most often use. Finally, we introduce a few reference examples.
Second, UITableView and its relatives.
1. UITableView
Reference:
https://developer.apple.com/library/ios/#documentation/uikit/reference/uitableview_class/reference/reference.html
1) Initialize the UITableView object
– initWithFrame:style:
Code generation method, if you do not need to use this method in the nib Riga TableView
2)配置TableView
– dequeueReusableCellWithIdentifier:
The method that must be implemented, with the tableview of the same life and death
style
Property//There are two kinds of uitableviewstyleplain, uitableviewstylegrouped, often used
– numberOfRowsInSection:
How many rows a section has, often with
– numberOfSections
How many sections a TableView have, often with
rowHeight
Property//Row height, and tableView:heightForRowAtIndexPath:
performance differences
separatorStyle
Split line between property//cell? Pending confirmation
separatorColor
Property//Ibid.
backgroundView
Property//TableView background view, this background view in all cells, header views, footer views after
tableHeaderView
A Headerview above the property//TableView, and the section header in delete are not a concept
tableFooterView
A Footerview below the property//TableView
sectionHeaderHeight
The height of the property//section header,
sectionFooterHeight
Property//sectjion footer Height
sectionIndexMinimumDisplayRowCount
Property//function pending confirmation? Reference example: theelements
3) Access to cells and sections
– cellForRowAtIndexPath: //根据IndexPath返回cell
– indexPathForCell: //根据cell返回它的indexPath,和上面的方法互补
– indexPathForRowAtPoint://根据一个几何点返回indexPath,如果超过边界返回nil
– indexPathsForRowsInRect: //根据一个几何的矩形返回矩形所覆盖的行,返回是一个indexPath数组
– visibleCells // 不清楚怎么用,待确认
– indexPathsForVisibleRows //同上
4) Rolling TableView
– scrollToRowAtIndexPath:atScrollPosition:animated: // 滚动到指定位置
– scrollToNearestSelectedRowAtScrollPosition:animated: // 同上
5) Management Sections
– indexPathForSelectedRow //返回选定行的indexPath,单行
– indexPathsForSelectedRows //返回选定行的indexPath数组,多行
– selectRowAtIndexPath:animated:scrollPosition: //根据indexPath选择一行
– deselectRowAtIndexPath:animated: //反选一行,有何用?
allowsSelection
Property//Whether the user is allowed to select a row
allowsMultipleSelection
Property//Whether to select multiple rows, the default is No. You can try the effect after yes, haha
allowsSelectionDuringEditing
Whether a row can be selected when the property//Edit mode
allowsMultipleSelectionDuringEditing
Multiple rows can be selected when property//edit mode
6) Inserting, deleting, moving lines and sections
– beginUpdates // 和endUpdates一起用,让插入、删除、选择操作同时动画,没用过
– endUpdates //
– insertRowsAtIndexPaths:withRowAnimation: //根据indexPath数组插入行
– deleteRowsAtIndexPaths:withRowAnimation: //根据indexPath数组删除行
– moveRowAtIndexPath:toIndexPath: //移动一行到另一行
– insertSections:withRowAnimation: //插入sections
– deleteSections:withRowAnimation: //删除sections
– moveSection:toSection: //移动section
7) Managing and editing cells
editing
Property//Yes into edit mode, TableView cell will appear to insert, delete, reorder the controls
– setEditing:animated: //设置进入退出编辑模式
8) Reload TableView
– reloadData // 重建整个表,包括cells、header、footer,indexs
– reloadRowsAtIndexPaths:withRowAnimation: // 改进,不用reload整个表
– reloadSections:withRowAnimation: // 同上
– reloadSectionIndexTitles // 同上
9) Access the drawing area of the TableView
– rectForSection: // 返回指定section的矩形
– rectForRowAtIndexPath: //返回indexPath指定行的矩形
– rectForFooterInSection: // 返回section的footer矩形
– rectForHeaderInSection: // 返回section的header矩形
Registering Nib Objects for Cell reuse
– registerNib:forCellReuseIdentifier: //
11) Managing delegates and data sources (important)
dataSource
The property//is usually used this way: mytableview.delegate = self; Self for Viewcontroller
delegate
The property// is usually used this way: Mytableview.datasource = self, Self is Viewcontroller
Summary:
UITableView User Guide-JG2014time 2014-09-26 17:17:00 Blog Park _jg2014
original http://www.cnblogs.com/yjg2014/p/3995293.html 1) Initialize the UITableView object
– initWithFrame:style:
Code generation method, if you do not need to use this method in the nib Riga TableView
2)配置TableView
– dequeueReusableCellWithIdentifier:
The method that must be implemented, with the tableview of the same life and death
style
Property//There are two kinds of uitableviewstyleplain, uitableviewstylegrouped, often used
– numberOfRowsInSection:
How many rows a section has, often with
– numberOfSections
How many sections a TableView have, often with
rowHeight
Property//Row height, and tableView:heightForRowAtIndexPath:
performance differences
separatorStyle
Split line between property//cell? Pending confirmation
separatorColor
Property//Ibid.
backgroundView
Property//TableView background view, this background view in all cells, header views, footer views after
tableHeaderView
A Headerview above the property//TableView, and the section header in delete are not a concept
tableFooterView
A Footerview below the property//TableView
sectionHeaderHeight
The height of the property//section header,
sectionFooterHeight
Property//sectjion footer Height
sectionIndexMinimumDisplayRowCount
Property//function pending confirmation? Reference Example: theelements
3) Access to cells and sections
– cellForRowAtIndexPath: //根据IndexPath返回cell
– indexPathForCell: //根据cell返回它的indexPath,和上面的方法互补
– indexPathForRowAtPoint://根据一个几何点返回indexPath,如果超过边界返回nil
– indexPathsForRowsInRect: //根据一个几何的矩形返回矩形所覆盖的行,返回是一个indexPath数组
– visibleCells // 不清楚怎么用,待确认
– indexPathsForVisibleRows //同上
4) Rolling TableView
– scrollToRowAtIndexPath:atScrollPosition:animated: // 滚动到指定位置
– scrollToNearestSelectedRowAtScrollPosition:animated: // 同上
5) Management Sections
– indexPathForSelectedRow //返回选定行的indexPath,单行
– indexPathsForSelectedRows //返回选定行的indexPath数组,多行
– selectRowAtIndexPath:animated:scrollPosition: //根据indexPath选择一行
– deselectRowAtIndexPath:animated: //反选一行,有何用?
allowsSelection
Property//Whether the user is allowed to select a row
allowsMultipleSelection
Property//Whether to select multiple rows, the default is No. You can try the effect after yes, haha
allowsSelectionDuringEditing
Whether a row can be selected when the property//Edit mode
allowsMultipleSelectionDuringEditing
Multiple rows can be selected when property//edit mode
6) Inserting, deleting, moving lines and sections
– beginUpdates // 和endUpdates一起用,让插入、删除、选择操作同时动画,没用过
– endUpdates //
– insertRowsAtIndexPaths:withRowAnimation: //根据indexPath数组插入行
– deleteRowsAtIndexPaths:withRowAnimation: //根据indexPath数组删除行
– moveRowAtIndexPath:toIndexPath: //移动一行到另一行
– insertSections:withRowAnimation: //插入sections
– deleteSections:withRowAnimation: //删除sections
– moveSection:toSection: //移动section
7) Managing and editing cells
editing
Property//Yes into edit mode, TableView cell will appear to insert, delete, reorder the controls
– setEditing:animated: //设置进入退出编辑模式
8) Reload TableView
– reloadData // 重建整个表,包括cells、header、footer,indexs
– reloadRowsAtIndexPaths:withRowAnimation: // 改进,不用reload整个表
– reloadSections:withRowAnimation: // 同上
– reloadSectionIndexTitles // 同上
9) Access the drawing area of the TableView
– rectForSection: // 返回指定section的矩形
– rectForRowAtIndexPath: //返回indexPath指定行的矩形
– rectForFooterInSection: // 返回section的footer矩形
– rectForHeaderInSection: // 返回section的header矩形
Registering Nib Objects for Cell reuse
– registerNib:forCellReuseIdentifier: //
11) Managing delegates and data sources (important)
dataSource
The property//is usually used this way: mytableview.delegate = self; Self for Viewcontroller
delegate
The property//is usually used this way: Mytableview.datasource = self; Self for Viewcontroller
Another small discovery is that when you turn on multiple selection, the CELL,UITABLEVIW you select automatically saves you indexpath to an array:
[Datalisttableview Indexpathsforselectedrows]
So you can get the currently selected cell
[Datalisttableview Visiblecells]; [Datalisttableview Indexpathsforvisiblerows];
UITableView User Guide