UITableView
TableView is a one-dimensional table, which is a uiscrollview subclass, so it is a scrolling list. It can be highly customizable, it gets all the customization information from its two different delegation, and the two different properties,data source, data source and delegate, are responsible for providing the data in the table, Delegate is responsible for data display. If you want to display multidimensional data, there are rows and columns, you can use sections or you can put it in a navigation controller.
Term describing the various parts of the plain style tableveiw:
The top thing is called the header, which is a uiview that can be added to the table, and it can be anything you want. At the bottom there is a footer, also a uiview. These grouped items are called section headers, which can be set with a string or view, and each row in the table is a uiview, called the UIView tableveiw cell.
Describe group-style tableveiw using exactly the same terms:
When there is a section, it is necessary to tell tableveiw how many section to build tableveiw and implement data source, and then it will ask you how many row in each section. Uitableviewdatasource
There are methods in data source protocol. There are three very important methods to implement, one is to show how many section in the table, the second is how many row each section has, and the third is the UITableView cell that returns each row to be drawn.
To see the last method, this is what the method looks like://nsindexpath to do is encapsulate section and row, so it has two attributes, one called section, and one called Row,section will tell you what section is currently, The row will tell you which row is in the current section.
-(UITableViewCell *) TableView: (UITableView *) sender Cellforrowatindexpath: (Nsindexpath *) Indexpath
Returns how many segments there are.
-(Nsinteger) Numberofsectionsintableview: (UITableView *) sender;
Returns how many elements are in the corresponding fragment, that is, how many rows.
-(Nsinteger) TableView: (UITableView *) sender Numberofrowsinsection: (nsinteger) Section;
uitableviewdelegate
The
Uitableviewdelegate controls how the table is drawn, not the data in the table, but how it is displayed, such as how high a cell is. Often data source and delegate are the same object, there are many did/will happen methods for this uitableviewcontroller,delegate, and the most important thing is that it notifies you when someone clicks on the row. The UITableView instance uses delegates in response to user interaction actions. The delegate tells the form to transfer responsibility for responding to these interactions to the specified object. This specified object is usually the Uitableviewcontroller controller object that owns the table view. Of course, the delegate must implement the Uitableviewdelegate protocol. The delegate method basically customizes the table structure:
Tableview:heightforrowatindexpath Returns the height of the specified row. tableview:heightforheaderinsection Returns the height of the header view area for the specified segment. tableview:heigthforfooterinsection Returns the height of the footer view area for the specified segment. Tableview:titleforheaderinsection returns the title of the header of the specified fragment, and if the section header has a return view, then title does not work. tableview:viewforheaderinsection Returns the view of the header for the specified segment, and if not, you can not return to view. Tableview:didselectrowatindexpath When a user selects a cell in a row, the callback uses this. The prerequisite is that a allowsselection property of TableView must be set to Yes. Tableview:accessorybuttontappedforrowwithindexpath responds to user clicks on the arrow on the right side of the cell. TableView:commitEditingStyle:editingStyleforRowAtIndexPath Notifies the user which cell is edited.
Therefore, through the above understanding, we know that UITableView instance initialization must set the Setdatasource and Setdelegate properties, specifying the data source and delegate object, respectively . The table view obtains configuration data from objects that follow the Uitableviewdelegate protocol, and obtains row data from objects that follow the Uitableviewdatasource protocol . The data source provides all the data that is required for the drawing, and the delegate is used only to configure the appearance of the table view and to handle some user interaction. code example:
UITableView *tableview = [[UITableView alloc] Initwithframe:cgrectmake (0, 0,, 420)];
[TableView setdelegate:self];
[TableView setdatasource:self];
[Self.view Addsubview:tableview];
[TableView release];
Note: In addition to the delegate method invocation, the UITableView instance also provides notifications. Notifications Use the default Nsnotificationcenter broadcast updates to allow the application's different threads to communicate with each other. The only official form notice in the 3.0 SDK is uitableviewselectiondidchangenotification.
In fact, the UITableView class inherits from the Uiscrollviewand is a special scrollview, which encapsulates the UITableViewCell cell control primarily. By default, all Uitableviewcontroller instances are automatically set to Uiscrollview delegates.
The
1. UITableView view is accessed through the TableView property.
2. Almost any string array can be used to set and populate tables.
3. To display a table, you must implement the 3 core methods of Numberofsectionsintableview, Numberofrowsinsection, and Cellforrowatindexpath to define the table structure and provide content display.
4. Reusable Cells is an efficient way for table view to save memory usage, and different ID identifiers should be used for different types of cells.
5. When you assign a new cell, you must check that the reused cells are available. (That is, check Dequeuereusablecellwithidentifier: Requested return value)
6. When a user selects a cell in a row, the callback method Tableview:didselectrowatindexpath: triggered.
7. Table styles are available in two styles: Uitableviewstyleplain (displayed by index), uitableviewstylegrouped (sorted by group).
8. The color settings for the selected cells are: Uitableviewcellselectionstyleblue, Uitableviewcellselectionstylegray, Uitableviewcellselectionstylenone three kinds of values.
9. Basic Table View cell types: Uitableviewcellstyledefault, Uitableviewcellstylesubtitle, UITableViewCellStyleValue1, There are four types of UITableViewCellStyleValue2. &NBSP
10. In general, the custom table view is actually a display layout that customizes the table row data directly, that is, by customizing the UITableViewCell cell. method is either to add a child view directly to the UITableViewCell, or subclass UITableViewCell to implement it. Excerpt from: http://www.cnblogs.com/lovecode/articles/2238309.html
Http://www.cnblogs.com/geory/archive/2013/02/27/2913618.html