UITableView User Guide

Source: Internet
Author: User

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
  •   styleProperty//There are two kinds of uitableviewstyleplain, uitableviewstylegrouped, often used
  • – numberOfRowsInSection:How many rows a section has, often with
  • – numberOfSectionsHow many sections a TableView have, often with
  •   rowHeightProperty//Row height, and tableView:heightForRowAtIndexPath: performance differences
  •   separatorStyleSplit line between property//cell? Pending confirmation
  •   separatorColorProperty//Ibid.
  •   backgroundViewProperty//TableView background view, this background view in all cells, header views, footer views after
  •   tableHeaderViewA Headerview above the property//TableView, and the section header in delete are not a concept
  •   tableFooterViewA Footerview below the property//TableView
  •   sectionHeaderHeightThe height of the property//section header,
  •   sectionFooterHeightProperty//sectjion footer Height
  •   sectionIndexMinimumDisplayRowCountProperty//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: //反选一行,有何用?
  •   allowsSelectionProperty//Whether the user is allowed to select a row
  •   allowsMultipleSelectionProperty//Whether to select multiple rows, the default is No. You can try the effect after yes, haha
  •   allowsSelectionDuringEditingWhether a row can be selected when the property//Edit mode
  •   allowsMultipleSelectionDuringEditingMultiple 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
    •   editingProperty//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)
    •   dataSourceThe property//is usually used this way: mytableview.delegate = self; Self for Viewcontroller
    •   delegateThe 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
  • styleProperty//There are two kinds of uitableviewstyleplain, uitableviewstylegrouped, often used
  • – numberOfRowsInSection:How many rows a section has, often with
  • – numberOfSectionsHow many sections a TableView have, often with
  • rowHeightProperty//Row height, and tableView:heightForRowAtIndexPath: performance differences
  • separatorStyleSplit line between property//cell? Pending confirmation
  • separatorColorProperty//Ibid.
  • backgroundViewProperty//TableView background view, this background view in all cells, header views, footer views after
  • tableHeaderViewA Headerview above the property//TableView, and the section header in delete are not a concept
  • tableFooterViewA Footerview below the property//TableView
  • sectionHeaderHeightThe height of the property//section header,
  • sectionFooterHeightProperty//sectjion footer Height
  • sectionIndexMinimumDisplayRowCountProperty//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: //反选一行,有何用?
    • allowsSelectionProperty//Whether the user is allowed to select a row
    • allowsMultipleSelectionProperty//Whether to select multiple rows, the default is No. You can try the effect after yes, haha
    • allowsSelectionDuringEditingWhether a row can be selected when the property//Edit mode
    • allowsMultipleSelectionDuringEditingMultiple 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
    • editingProperty//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)
    • dataSourceThe property//is usually used this way: mytableview.delegate = self; Self for Viewcontroller
    • delegateThe 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.