Beginning Table Views · IndexPaths | Ray Wenderlich


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5995-beginning-table-views/lessons/6

Hi Brian,

I have a question about the way that you added text to the cells of the table by first adding a label and then changing the text of that label.

Can’t you add text to the cell without first adding a label? Can’t you do something like:

cell.textLabel.text = “Run a Marathon”?

Is there a reason that you need to add the label first and then add the text to that label rather than add the text directly to the cell?

Thanks!

Mary

Hi Mary,

Yes, default cells come with a title label that you can simply assign a string. Those also come with an image. We could have just easily have done that but we wanted to stress that cells are customizable via. storyboards. But there’s no problem simply assigning a string to the titleLabel. I just did that recently in a project this week.

I hope that helps!

Thanks!

Thank you so much! It does help!

Hi Brian, @bdmoakley

I have a question on indexPath and Tag. You mentioned that indexPath “represents the location of a table view cell.” And you introduced a new concept of ‘Tag,’ which seems to be very similar to what indexPath does: it also represents the location of a table view cell. So, does this also mean that when I want to change contents, let say, a label, I can use both ‘Tag’ and ‘indexPath(row: 0, section: 0)??’

What exactly is a difference between Tag and IndexPath?

Ive went through the tutorials a couple of times and it seems like its just a walkthrough. I can’t keep up and even If I can follow through, I definitely don’t understand why we’re doing things the way we are which is basically the reason why I signed up for this.

We’re in the process of reviewing the course and will most likely break it into two courses. If you get stuck, then don’t sweat it. Just keep moving forward. Confusion is part of growing. Mind you, it’s not fun but it’s process. I hope that helps!

Hi Juno,

A tag is an arbitrary number. It means whatever you want to mean. When you assign tags to views, you’ll have to use that tag to get that view. You can set the tag to be anything - 1, 100, 534 - it doesn’t matter.

An index path is the specific location of an item. You can think of it like an address. It is specific. For a table view, we use it to find the location of cells.

In summation, a tag is a number that assign to views. The number is arbitrary. You can use it to fetch views. An index path is a specific location of an item.

I hope that helps!

There is a slight confusion with the image at 0:20 in the video. The image seems to be a bit wrong since 2 should point to the third row. And it also doesn’t follow what the instructor says.

Small thing, but can be confusing to a beginner. Great content nonetheless!

@bdmoakley Can you please help with this when you get a chance? Thank you - much appreciated! :]