1.Table View’s Content Type
a. dynamic prototype
Use a dynamic prototype when multiple cells in a table should use the same layout to display information. Dynamic content is managed by the table view data source (the table view controller) at runtime, with an arbitrary number of cells.
b. static content
Use static content to design the overall layout of the table, including the total number of cells. A table view with static content has a fixed set of cells that you can configure at design time. You can also configure other static data elements such as section headers. Use static cells when a table does not change its layout, regardless of the specific information it displays.
2.动态和静态content的创建和配置
a. Calling sequence for creating and configuring a table view

-
The view controller creates a
UITableViewinstance in a certain frame and style. It can do this either programmatically or in a storyboard. The frame is usually set to the screen frame, minus the height of the status bar or, in a navigation-based app, to the screen frame minus the heights of the status bar and the navigation bar. The view controller may also set global properties of the table view at this point, such as its autoresizing behavior or a global row height.To learn how to create table views in a storyboard and programmatically, see “Creating a Table View Using a Storyboard” and “Creating a Table View Programmatically.”
-
The view controller sets the data source and delegate of the table view and sends a
reloadDatamessage to it. The data source must adopt theUITableViewDataSourceprotocol, and the delegate must adopt theUITableViewDelegateprotocol. -
The data source receives a
numberOfSectionsInTableView:message from theUITableViewobject and returns the number of sections in the table view. Although this is an optional protocol method, the data source must implement it if the table view has more than one section. -
For each section, the data source receives a
tableView:numberOfRowsInSection:message and responds by returning the number of rows for the section. -
The data source receives a
tableView:cellForRowAtIndexPath:message for each visible row in the table view. It responds by configuring and returning aUITableViewCellobject for each row. TheUITableViewobject uses this cell to draw the row.
b. static content
if a table view is static then you should not implement any data source methods. The configuration of the table view is known at compile time, so UIKit can get this information from the storyboard at runtime. However, you still need to populate a static table view with data from your data model. “Populating a Static Table View With Data” shows an example of how a table view controller could load user data in a static table view.
Populating a static table view with data
- (void)viewDidLoad |
{
|
[super viewDidLoad]; |
BirdSighting *theSighting = self.sighting; |
static NSDateFormatter *formatter = nil; |
if (formatter == nil) {
|
formatter = [[NSDateFormatter alloc] init]; |
[formatter setDateStyle:NSDateFormatterMediumStyle]; |
} |
if (theSighting) {
|
self.birdNameLabel.text = theSighting.name; |
self.locationLabel.text = theSighting.location; |
self.dateLabel.text = [formatter stringFromDate:(NSDate*)theSighting.date]; |
} |
} |
The table view is populated with data in the UIViewController method viewDidLoad, which is called after the view is loaded into memory. The data is passed to the table view controller in the sighting object, which is set in the previous view controller’s prepareForSegue:sender: method. The propertiesbirdNameLabel, locationLabel, and dateLabel are outlets connected to labels in the static table view.
出处
http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/CreateConfigureTableView/CreateConfigureTableView.html#//apple_ref/doc/uid/TP40007451-CH6-SW10
浙公网安备 33010602011771号