TableView Setup
Start course
1h 22m

This course delves into Object-Oriented Programming (OOP), covering its main components, and then putting these into practice by walking you through the creation of an app using OOP.

Learning Objectives

  • Learn about classes and how you can leverage them in your code.
  • Learn concepts such as Enum, Inheritance, and Access Levels
  • Understand how these can be used to build apps

Intended Audience

This course is intended for beginners who want to learn how to build apps using Swift.


To the most out of this course, you should have some basic understanding of programming and computer science in general.



Hi. Within this lecture, we're going to set our TableView app so that we can use it in our View Controller. And also we're going to find some Simpson images and names and jobs. So, first of all I suggest you pause the video and do the tableView set up on your own. This is going to be exactly the same way that we have done in the landmark book application. So, pause the video and try to do it on your own. I hope you made it. If so, congratulations. If you couldn't just don't worry, I'm going to show you how it's done.

So, remember we have to add UITableViewDelegate and UITableViewDataSource in here. So, this will make our View Controller a delegate and data source of our table view and this will give us a chance to reach those functions related to tableViews. And remember we have to call two functions in here in order to make this work and those are the number of rowsInSection and cellForRawAt indexPath. And that's how we set our tableView app later on when we create our model we will do the related adjustments so that we can display the data in tableView as well. So, how do we do it?

Remember we can come over here and say number of rowsInSection. So, this one double click on this and it will bring up the function. And here we have to return the number, so this number will be 10 right now. Later on we're going to adjust it. And we have to call for cellForRawAt indexPath. That's where we have to return a cell, so I'm going to create a cell first. And in order to create a cell you can just write let cell = UITableViewCell, okay? UITableViewCell and we can just display text in here by saying cell.textLabel?.test = test or Simpson or Homer Simpson, and then we can return this cell. And, of course, this is going to be adjusted later on according to our arrays. Right now we are done, but let us see if this works. And this won't work. Maybe you realized that I forgot something.

So, let's run and see if this display Homer Simpson 10 times. And as you can see, we're just seeing some empty rows because I forgot to make our TableView data source and TableViewDelegate to equal to self  to View Controller. In order to do that, come over here and say tableView.dataSource is self and tableView.delegate is again self. So, this will make our viewController the delegate and dataSource of our tableView. So, now if I run this on my simulator I will see Homer Simpson 10 times. So, this is exactly what we want.

Now, it's time to really find some Simpsons and show them in our tableView rather than having some test dummy variables in here. And even though we're just going to display the names in the tableView, we're going to need some images and jobs as well. And remember in our details viewController, we're going to display the name and the job and the image. So, here comes the boring part. We have to go to the Google and find some images and names and jobs.

So, we're going to do that step by step again. So, let me go to Google and you can just search for Simpsons or Simpson characters. So, it's not going to be South Park characters, it's going to be Simpson characters. And of course it doesn't necessarily matter. So, you can just go for South Park as well, but I'm going to go for Simpsons because we made something with South Park, right? And this is good. So, we're looking something like this, something like this image. So, let me go to this Homer Simpson or I believe there is a Wiki for Simpson's here Wikisimpsons.

So, I'm going to go to this Wikisimpsons so maybe we can get a lot more information regarding to Simpsons like we're going to need the job but maybe you want to display other features like birthplace, or I don't know, maybe birthday as well. So, I'm going to save this file. So, let me see Homer Simpson is in my Downloads. And we can get the jobs and other information here from this website as well. And if you cannot find this website, you can just go for Google and just search for Homer Simpson and find a related image. So, let me search. Do we have have some characters here? Yeah, I believe so. Let me click on the characters, and we have so much characters in the Simpsonpedia I believe... Simpsonwiki, I believe so. I believe we have to search one by one for example. We have Bart Simpson over here. Let me click on that one. And this doesn't display the Bart Simpson as I want it to be. So, this one does. So, let me save this file. Let me save it to Downloads. And here we go. Actually Job of Bart Simpson should be just student. So, let's go for other characters and just find the images. We can really make up the jobs. We're just doing this for an example,

so let me search for Marge Simpson. Okay, I'm going to download this and let me go for Lisa Simpson, okay? Let's go for Lisa and save it to Downloads. Let's do one more. We have Homer, Marge, Bart, and Lisa. So, let's go for the baby. Her name was Maggie, I believe Maggie Simpson, so not this one. Maybe we should just write it like Maggie with G and E. Maggie Simpson? Yes, Margaret Evelyn Simpson, I should have done this in Google really. So, the Simpsonwiki thing is a nightmare. So, we have five images I believe. That's okay for right now. So, let me rename all of them. So, this is going to be Bart, this is going to be Lisa, this is going to be Maggie, and this is Marge. And finally we have Homer. So, that's good. And I'm just going to take all of this and I'm going to embed them in my assets folder over here, okay? So, let me open this drag and drop, and here we go. We are ready. So, what are we going to do? We're going to create a model. We're going to create a Simpson class in which we can have these images in which we can have the jobs and the names as well and we know how to do that right because we just got out of objected-oriented programming lectures. So, we're going to stop here, and within the next lecture, we're going to do this class of Simpson.


About the Author
Learning Paths

Atil is an instructor at Bogazici University, where he graduated back in 2010. He is also co-founder of Academy Club, which provides training, and Pera Games, which operates in the mobile gaming industry.

Covered Topics