This document describes various methods, properties, delegates, and data sources for UITableView. The purpose of this article is simply to summarize the usage of UITableView, and the detailed examples are described separately.
1 Data Source Uitableviewdatasource protocol
01 returns the number of groups (sections), the default is 1, if only 1 sets of data, you can not implement the method.
-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView
02 returns the number of rows for a group that is determined by the value of section
-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section
03 returns the UITableViewCell of a group of one row, determined by Indexpath,
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath,
04 returns the header of a group
-(NSString *) TableView: (UITableView *) TableView titleforheaderinsection: (nsinteger) Section
05 returns the trailing title of a group
-(NSString *) TableView: (UITableView *) TableView titleforfooterinsection: (nsinteger) Section
2 Delegated Uitableviewdatadelegate Agreement
01 Set the cell height.
-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath
02 When a row is selected , the method is called
-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath
03 Returns the grouped head view , the following two methods must be used at the same time , otherwise the problem
-(UIView *) TableView: (UITableView *) TableView viewforheaderinsection: (nsinteger) Section
-(CGFloat) TableView: (UITableView *) TableView heightforheaderinsection: (nsinteger) Section
3 Common Properties and methods of UITableView
01 Set how the table view is displayed: tiled or multiple groups of displays
@property (Nonatomic, ReadOnly) Uitableviewstyle style;
02 Set the height of the cell, set by the RowHeight property, and all row heights are the same
@property (nonatomic) CGFloat rowHeight;
03 Setting the Split line style
@property (nonatomic) Uitableviewcellseparatorstyle Separatorstyle;
04 Set the split Line color
@property (nonatomic,retain) Uicolor *separatorcolor;
Set the head and bottom view of the TableView with the width of the default as wide as tableveiw
Tableview.tableheaderview = [UIButton buttonwithtype:uibuttontypecontactadd];
Tableview.tablefooterview = [[Uiswitch alloc] init];
set whether to hide vertical scroll bars
self. Tableview.showsverticalscrollindicator = NO;
07 Set whether the cell can be selected
self. Tableview.allowsselection = NO;
. let tableveiw scroll to a line
-(void) Scrolltorowatindexpath: (nsindexpath *) Indexpath atscrollposition: ( Uitableviewscrollposition) scrollposition animated: (BOOL) animated;
4 UITableViewCell related properties and methods set the view and method for each row
01 Secondary controls per cell
@property (nonatomic) Uitableviewcellaccessorytype Accessorytype; The rightmost control of each row , not displayed by default
@property (nonatomic, retain) UIView *accessoryview;
The background view of the cell, and the background color. The background of the cell can be set through both BackgroundColor and Backgroundview , but Backgroundview Higher priority than backgroundcolor .
@property (nonatomic, retain) UIView *backgroundview;
@property (nonatomic, retain) UIView *selectedbackgroundview; set the background of the selected state
Geneva cell display, the default is to save the Contentview
@property ( nonatomic Span style= "line-height:1.5;" class= "S3" >readonly retain uiview *contentview ; cell display default of three view, contentview Span style= "line-height:1.5;" class= "S2" in
@property (nonatomic, readonly, retain) Uiimageview *imageview Ns_available_ios (3_0); //default is nil. Image view would be created if necessary.
@property (nonatomic, readonly, retain) UILabel *textlabel Ns_available_ios (3_0); //default is nil. Label would be created if necessary
@property (nonatomic, readonly, retain) UILabel *detailtextlabel
5 cell optimization
0 1, when a cell appears on the screen, the system will call the cell generation method
Static NSString *identifier = @ "hero"; // define variables to save values for reuse tags
UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:identifier]; //1. go to the cache pool first to find out if there is a condition that satisfies the Cell
if (cell = = nil) {//2. If there are no qualifying cells in the cache pool , create a cell of your own
cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstylesubtitle Reuseidentifier:identifier] ; //3. Create Cell, and set a unique tag
}
02. The iOS7 has been automatically optimized to Register a cell class or a nib file , The system automatically optimizes the generation of the cell
1.registerclass:forcellreuseidentifier:
2.Dequeuereusablecellwithidentifier:forindexpath: