How To Use Table View Cells In iPhone?

To show how to use custom cells, we’re going to create a new application with another table view, and we,re going to display two lines of information to the user. our application will display the name and color. We’ll display both of those information in the same table cell by adding subviews to the table view cell.

Step 1: Create a new Xcode project using the view-based application template.

Step 2: Double click .xib files and add a Table View, and sei its delegate and datasource to File’s Owner. Save it, and go back to Xcode.

Step 3: We need to add some code in the header file. We have define two constants and assign tags to some of the subviews that we’ll be adding to the table view cell. Add four subviews to the cell , and two of those need to be changed for every row.

 

 

 

Step 4: In our controller, we need to set up some data to use, and then implement the table data source methods to feed that data to the table. The viewDidLoad method this time creates a bunch of dictionaries. Each dictionary contains the name and color information for one row in the table. The name for that row is held in the dictionary under the key Name, and color is held under the Color.

 

 

 

Step  5: Compile and run your application, you should get rows with two lines of data in it, Just show in figure 1.

Figure 1: Adding subviews to the table view cell can give you multiline rows.

You can downloaded SourceCode from here Cells 2