In many mobile should use, can see a variety of tabular data,
• In iOS, to implement tabular data show, the most common practice is to make the UITableView
UITableView inherit from Uiscrollview, so? Support vertical scrolling, and excellent performance
UITableView two styles, one is only one group, there is also a number of the number of such as:
How to show data?
UITableView need? A data source (DataSource) to display the data,
UITableView will you query the data source? How many? rows of data and the number of each of the lines showing what data, etc.
Any OC object that complies with the Uitableviewdatasource protocol can be a UITableView data source
TableView the process of showing data
1. How to use the next surface of the data source? How many sets of data are there?
-(Nsinteger) Numberofsectionsintableview: (UITableView
*) TableView;
2. What is the bottom of the data source? method to know how much each group has? Row data
-(Nsinteger) TableView: (UITableView *) TableView
Numberofrowsinsection: (nsinteger) Section;
3. How to use the next surface of the data source to know what to do with each one?
-(UITableViewCell *) TableView: (UITableView *) Tableviewcellforrowatindexpath: (Nsindexpath *) Indexpath;
Of course, we also have to implement the Protocol, otherwise, these proxy methods will not be used. Property (nonatomic, assign) ID <UITableViewDataSource> dataSource; UITableView
With these 3 proxy methods, you can bind the data that you want to display on the page to the UITableView.
Two cell introduction
UITableView every one of them? A UITableViewCell that initializes a line by DataSource's Tableview:cellforrowatindexpath: Method
UITableViewCell There's a default? Sub-view: Contentview,contentview is the content of the UITableViewCell? Parent view, can be shown? Some auxiliary reference view ·
The work of the auxiliary reference view is an indication of the icon of a table showing action, which can be displayed by setting UITableViewCell Accessorytype,
The default is Uitableviewcellaccessorynone (does not show auxiliary reference), the other values are as follows:
Uitableviewcellaccessorydisclosureindicator
Uitableviewcellaccessorydetaildisclosurebutton
Uitableviewcellaccessorycheckmark
• You can also use the Accessoryview property of the cell to customize the auxiliary reference view
UITableViewCell's Contentview
Contentview The default is 3? Child view
2 of them are Uilabel (accessed via UITableViewCell's Textlabel and Detailtextlabel properties)
3rd one is uiimageview (accessed via UITableViewCell's ImageView property)
UITableViewCell? A Uitableviewcellstyle property, which is used to determine which of the contentview to use? Child views, and the location of the child view in the Contentview
The principle of the cell's heavy use
iOS devices have limited memory, and if you use UITableView to display thousands of data, you need thousands of UITableViewCell objects, which will deplete the memory of your iOS device.
To solve this problem, you need to use the UITableViewCell object
• How to use the principle: when scrolling the list, part of the UITableViewCell will be removed from the window?? Mouth, UITableView will be the window?? UITableViewCell in the mouth? In an object pool, wait for heavy.
When UITableView asks DataSource to return UITableViewCell, DataSource looks at the object pool first.
If there are uitableviewcell,datasource in the pool? Configure the UITableViewCell with the new data,
Then return to the UITableView, show the window again?? In the mouth, from the? To avoid creating new objects
• What's more? A very important question: Is it sometimes necessary? Custom UITableViewCell (? A subclass inherits UITableViewCell),
? And every one of them? It must be the same UITableViewCell, so? A UITableView may have different types of UITableViewCell,
There will also be many different types of UITableViewCell in the object pool, so UITableView may get the wrong type of UITableViewCell when using UITableViewCell with heavy weight.
• Solution: UITableViewCell has a nsstring *reuseidentifier attribute that can be used in the initial
When you UITableViewCell? A specific string identifier to set the Reuseidentifier (???????.). Use the UITableViewCell class name.
When UITableView asks DataSource to return UITableViewCell, first pass through? A string is identified to the object pool to find the corresponding type of UITableViewCell object.
If you have one, use it, and if not, pass it to the string identifier to initialize? A UITableViewCell object
Cell's heavy code-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{?/ /1. Definition of a cell the static nsstring *id = @ "Mjcell";//2. Remove from the cache pool Celluitableviewcell *cell = [TableView dequeuereusablecellwithidentifier:id];//3. If the buffer pool does not have a cell if (cell = = nil) { cell = [[UITableViewCell alloc] InitWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:ID];} 4. Set the cell's properties ... return cell;}
IOS UITableView Introduction