Custom uitableview cell in Swift

The aim of this post is to show how to build a Custom SWIFTed TableViewCell view cell. I have found several shallow examples with the default cell. But soon you will discover that will not fit a real sample project situation. I have found several difficulties from moving to Swift, that took me more time than I expected and that pushed me also to write this post.

The custom table view cell

I have just created a new Single View Project Application  in the default view controller  and added a new NSObject class that extends from uitableviewcell.

Captura de pantalla 2015-07-10 a las 18.54.54

 

Captura de pantalla 2015-07-10 a las 18.56.24

 

The storyboard

I have added a table view controller and a tableview cell with an image view and a label.

Captura de pantalla 2015-07-10 a las 19.02.50

Now is time to setup the custom table view cell. Firstly the  new  class associated to the cell:

Captura de pantalla 2015-07-10 a las 19.07.15

And secondly set the cell identifier:

Captura de pantalla 2015-07-10 a las 19.07.40

The View Controller

Now it is time for connecting the storyboard with the source code. Lets start off with the main view controller:

I have mapped the tableview to tbvData, and added the minimum uitableview delegates. The table view is filled with 3 elements contained in two arrays (items and images).

The table view cell

In the custom cell I have added an image view and a label as an example. This is the code that  configures the cell:

 

Finally

Captura de pantalla 2015-07-11 a las 14.58.34

You can get also find the code here

Leave a Reply

Your email address will not be published.