I. Overview
We often need to display a large amount of data, such as the iPhone's built-in Address Book application. Uitableview is a subclass of uiscrollview. On the iPhone, the table view is a column on the iPhone with multiple rows. you can scroll up or down to view more data. From the user's perspective, creating a table view is to complete the following three functions:
- Create a table View
- Provide text or images for each line
- When you select a row, make a response
A table view must have a data source, which is achieved through the uitableviewdatasource protocol. In addition, the table view uses the uitableviewdelegate protocol to perform operations on the table view. Generally, you create a subclass of uitableviewcontroller and then operate the data source and table view on this subclass.
1.1 table view type
Table views have two display styles:
1. ungrouped display --- uitableviewstyleplain
2. group display --- uitableviewstylegrouped
For the group structure, each group is called a section, and each row in a section is called a table cell)
Ii. Common uitableview Methods
2.1 initialize a table View
-(ID) initwithframe :( cgrect) frame style :( uitableviewstyle) style;
2.2 table view configuration method
-(Uitableviewcell *) dequeuereusablecellwithidentifier :( nsstring *) identifier; // you can find a uitableviewcell object based on the unique identifier.
-(Nsinteger) numberofrowsinsection :( nsinteger) Section; // returns the number of rows in the table view of the specified section.
-(Nsinteger) numberofsections; // return the number of sections in the table view.
2.3 access section and form element (uitableviewcell)
-(Uitableviewcell *) cellforrowatindexpath :( nsindexpath *) indexpath; // return the form element of the specified nsindexpath, nsindexpath objectRepresentativeInOneNested ArraySetTreeOfSpecific NodeOfPath.This roadCalledIndexPath. Here, you only need to understand nsindexpath as a path that represents the form Element location. According to this nsindexpath path, you can locate the corresponding form element.
-(Nsindexpath *) indexpathforcell :( uitableviewcell *) cell; // return nsindexpath information of the specified form Element
-(Nsindexpath *) indexpathforrowatpoint :( cgpoint) point; // returnNsindexpath
-(Nsarray *) indexpathsforrowsinrect :( cgrect) rect; // returns the nsindexpath information array of the specified cgrect.
-(Nsarray *) visiblecells; // returns the visible uitableviewcell Array
-(Nsarray *) indexpathsforvisiblerows; // return the value of the visible form ElementNsindexpath path information array
2.4 Management Section
-(Nsindexpath *) indexpathforselectedrow; // returnsNsindexpath
-(Void) selectrowatindexpath :( nsindexpath *) indexpath animated :( bool) animated scrollposition :( uitableviewscrollposition) scrollposition ;//
-(Void) deselectrowatindexpath :( nsindexpath *) indexpath animated :( bool) animated ;//
2.5 insert and delete form elements (uitableviewcell)
-(Void) beginupdates
-(Void) endupdates
-(Void) insertrowsatindexpaths :( nsarray *) indexpaths withrowanimation :( uitableviewrowanimation) Animation
-(Void) deleterowsatindexpaths :( nsarray *) indexpaths withrowanimation :( uitableviewrowanimation) Animation
-(Void) insertsections :( nsindexset *) Sections withrowanimation :( uitableviewrowanimation) Animation
-(Void) deletesections :( nsindexset *) Sections withrowanimation :( uitableviewrowanimation) Animation
-(Void) setediting :( bool) Editing animated :( bool) animate
2.6 loading table View data
-(Void) reloaddata
-(Void) reloadrowsatindexpaths :( nsarray *) indexpaths withrowanimation :( uitableviewrowanimation) Animation
-(Void) reloadsections :( nsindexset *) Sections withrowanimation :( uitableviewrowanimation) Animation
-(Void) reloadsectionindextitles