iPhone App Development: Table View Controller - Day One

Introduction

In this article, which is the first article on iOS Application development series, we can see how we create the table view controller in iOS, and how we put the data in it. We will be describing briefly about the table view and give some common method, which is very beneficial and mandatory, when you show the data.

Step 1

Create a new project and give the name table view. In this, I can’t show the image of creating the project. Simply, give the the project name and your project is created. Drag and drop the table view on the view controller and adjust the size to the controller screen.

controller

Step 2

Connect the datasource to the view controller (yellow circle). You can see that I connected the datasource to the view controller.

viewcontroller

Move to the SwiftController. In the file, first add the protocol UITableViewDataSource and the make an array which is shown in the table view.

protocol

Let keyword is basically the constant keyword and it means that the value can’t be changed after declaration.

Step 3

After declaring an array and importing the protocol, your Xcode prompts the error because there is some method which is mandatory to be implemented in a table view,  in which three methods are there and you must implement it.

In the table view, you see that in one cell of how many sections do we need at this moment, I need only one section.

section

In this method, we give the code of how many values you can print in the table view; for example,  if you give 5, it means any string appears only 5 times in a table. Now, I select the the array name and then give count keyword; its purpose is that by doing this code; we are not aware of the total value; we just make the array end and print all the values in the table view by writing this code.

code

In this method, we assign which course name is viewed in each and it looks  like this: First click on the storyboard and then click the table view in the left toolbar.  You will see the identifier box, type the cell in it and then come back to your method. In the first line, we declare the constant with cell and use one method here. The purpose of this method is that when the list of courses is shown and you drop down the cursor, the upper items are not saved in the memory and immediately drop out from the memory.

In the second line, we declare the new constant and calculate the index path of the row and an index. We print in the text label, which is a standard way and then in the  last we return the cell. After doing this, run the app and you see that the items are shown in the table view.

code

After running the app, you see that the items are shown in the table view. In the next article, we are moving to some dynamic table view items and are going to work on it.

view


Similar Articles