Dealing With Duplicated Data and Affected Cell in UITableViewCell

George Joseph K
Sep 7, 2020 · 3 min read
Simple Illustration about Table

As you know, UITableView really helps developers and designers to display the data simply. The main component of UITableView is the cell (UITableViewCell). All of your data will be displayed in the table through the cells. A set of cells will form a table. You can read full documentation and implementation trough the official documentation on the Apple Developer site.

Personally, In the early days of my exploration with UITableView. I had some issues in using UITableView. I set one cell to “active” condition, but after scrolling down the table I found out that other cells were affected with ✅ emoji and constantly duplicated to other cells below.

OH DANG!

As a beginner, I didn’t know why it happened. I tried to ask my mentors at at the Apple Developer Academy, where I used to be enrolled not long ago. Later, we found out that Swift is using “dequeReusableCell” to save its memory use and boost its performance. What do we need to do if we want to display 1000 data? Instead of creating 1000 cells, we just need to create a little visible cell (5–6) and reuse those cells to display another data. That “reuse” thing also caused this to happen. The “active status” was duplicated to another cell after I scrolled down the table. I’ve already found further explanation about “reuse thing” problems. Read this before you continue — > Why we use dequeueReusableCellWithIdentifier and this.

Based on what I’ve read, both of those articles suggest resetting the cell using prepareForReuse(). Just simply change the alpha, isEnabled condition, color, attribute, and the default value of your cell. Wow, it seemed super easy. But wait a minute! Take a look at what Apple recommends us not to do.

It will affect its performance they said
Whoa, so what must we do with our cells?

After a long journey of digging the internet. I tried to do something with my cell Swift file. I made a simple public function to reset the cell view and call it from my view controller file. This way, we don’t need to reset first and set after. Just call that public function from ViewController.swift file and you can update your cell automatically.

Simple solution to reset and update your cell
Make a public function and configure the view based on “isActive” condition
Call the public function that we created before at TableCustomCell.swift from our ViewController.swift

I have already implemented that prepareForReuse() solution and public function solution. So far, I don’t have any issues with my code, but sometimes I get new duplicated image errors when dealing with updating imageView in cell, but I think that’s another case.

Thanks for your attention and wait for another story about “Dealing with imageView in Cell” soon!

The Startup

Get smarter at building your thing. Join The Startup’s +787K followers.

By The Startup

Get smarter at building your thing. Subscribe to receive The Startup's top 10 most read stories — delivered straight into your inbox, once a week. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

George Joseph K

Written by

iOS Developer, Apple Developer Academy Cohort 2 Alumni

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +787K followers.

George Joseph K

Written by

iOS Developer, Apple Developer Academy Cohort 2 Alumni

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +787K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store