Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
How Are Table View Cells Reused?1:15 with Amit Bijlani
The table view delegate contains a method called cellForRowAtIndexPath which reuses table view cells. The method dequeueReusableCellWithIdentifier reuses cell for efficient use of memory management.
We successfully modified the Master-Detail template to display a list of blog titles,
but there's still one mysterious functionality which we did not cover.
How are the table view cells created or reused?
We know that the method cellForRowAtIndexPath
is responsible for creating the table view cells.
If we took away the dequeueReusableCellWithIdentifier
and just allocated and initialized a new table view cell for each row
that needed to be displayed within the table view,
then we would have as many rows as the number of items in our array.
This is bad because if we had 1,000 rows in our array,
we would have to allocate 1,000 table view cells.
This is problematic because it would make our application horribly slow,
rendering it useless.
By adding the following line, we enable the table view to efficiently manage the cells.
By using dequeueReusableCellWithIdentifier,
each cell has an identifier which is specified in the storyboard.
When the table view cell scrolls beyond the screen,
the table view then marks it for reusability and is able to recycle it for a new row.
You need to sign up for Treehouse in order to download course files.Sign up