# Beginning Table Views · Challenge: Updating the Controller | Ray Wenderlich

**URL:** <https://forums.kodeco.com/t/beginning-table-views-challenge-updating-the-controller-ray-wenderlich/47867>\
**Category:** 🎓 Courses & Articles\
**Created:** [August 31, 2018, 6:05pm UTC](https://forums.kodeco.com/t/beginning-table-views-challenge-updating-the-controller-ray-wenderlich/47867 "2018-08-31T18:05:01Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![bdmoakley](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/bdmoakley/32/108772_2.png) [@bdmoakley](https://forums.kodeco.com/u/bdmoakley)\
**Post date:** [August 31, 2018, 6:05pm UTC](https://forums.kodeco.com/t/beginning-table-views-challenge-updating-the-controller-ray-wenderlich/47867/1 "2018-08-31T18:05:01Z")

</div>

* * *
This is a companion discussion topic for the original entry at [https://www.raywenderlich.com/5995-beginning-table-views/lessons/18](https://www.raywenderlich.com/5995-beginning-table-views/lessons/18)

---

<div class="post-metadata">

**Author:** ![navneetbugalia](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@navneetbugalia](https://forums.kodeco.com/u/navneetbugalia)\
**Post date:** [August 31, 2018, 6:09pm UTC](https://forums.kodeco.com/t/beginning-table-views-challenge-updating-the-controller-ray-wenderlich/47867/2 "2018-08-31T18:09:25Z")

</div>

when we are doing cell.accessorytype = .none or .checkmark isn’t it sufficient to make the cell checked or unchecked , WHY are we doing todoList.todos[indexpath.row].checked = !of the same thing

i mean we are repeating the same thing !!  
Somebody help me and reply asap

---

<div class="post-metadata">

**Author:** ![bdmoakley](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/bdmoakley/32/108772_2.png) [@bdmoakley](https://forums.kodeco.com/u/bdmoakley)\
**Post date:** [August 31, 2018, 7:09pm UTC](https://forums.kodeco.com/t/beginning-table-views-challenge-updating-the-controller-ray-wenderlich/47867/3 "2018-08-31T19:09:52Z")

</div>

You are actually doing two different things. First, you are updating the cell to show either a checkmark or no checkmark. The second thing you are doing is updating the class which represents that checkmark.

If you didn’t do the second part, then you would never be able to uncheck the checkmark. Try it out. Delete the line of code after the if block and run it. You’ll quickly see why it’s necessary.

I hope that helps!

---

<div class="post-metadata">

**Author:** ![berktv](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@berktv](https://forums.kodeco.com/u/berktv)\
**Post date:** [September 9, 2018, 8:48pm UTC](https://forums.kodeco.com/t/beginning-table-views-challenge-updating-the-controller-ray-wenderlich/47867/4 "2018-09-09T20:48:16Z")

</div>

Hi, @bdmoakley! Why do we use `todoList.todos[indexPath.row].checked = !isChecked` inside `configureCheckmark`? This command inverts initial state of `checklistItem` and creates buggy behavior when table cell appears on screen every time when the application reuses it. Looks like we need set `todoList.todos[indexPath.row].checked` inside `tableView(didSelectRowAt)` only.

 ![strange%20behaviour](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/0/e/0e2ffc8fcc1681e708bbc94aa2d6e776406c1401.gif)

---

<div class="post-metadata">

**Author:** ![bdmoakley](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/bdmoakley/32/108772_2.png) [@bdmoakley](https://forums.kodeco.com/u/bdmoakley)\
**Post date:** [September 18, 2018, 3:47pm UTC](https://forums.kodeco.com/t/beginning-table-views-challenge-updating-the-controller-ray-wenderlich/47867/5 "2018-09-18T15:47:55Z")

</div>

Looks like a bug that I missed. I’ll take a look and see what I can do. Thanks for letting me know.

---

<div class="post-metadata">

**Author:** ![ollybess](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/ollybess/32/79544_2.png) [@ollybess](https://forums.kodeco.com/u/ollybess)\
**Post date:** [April 7, 2019, 11:48am UTC](https://forums.kodeco.com/t/beginning-table-views-challenge-updating-the-controller-ray-wenderlich/47867/6 "2019-04-07T11:48:59Z")

</div>

Hey!  
In the end of lesson:  
Why I cannot type something like: isChecked = !isChecked ?  
Before the transformation it looked like row0Item.checked = !row0Item.checked, which looks similar with my suggestion above.

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [April 30, 2019, 3:15am UTC](https://forums.kodeco.com/t/beginning-table-views-challenge-updating-the-controller-ray-wenderlich/47867/7 "2019-04-30T03:15:18Z")

</div>

@ollybess Do you still have issues with this?

---

<div class="post-metadata">

**Author:** ![jclau](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jclau/32/81494_2.png) [@jclau](https://forums.kodeco.com/u/jclau)\
**Post date:** [July 5, 2019, 9:49am UTC](https://forums.kodeco.com/t/beginning-table-views-challenge-updating-the-controller-ray-wenderlich/47867/8 "2019-07-05T09:49:07Z")

</div>

Hi

Could explain a bit more what this one:  
if let label = cell.viewWithTag(1000) as? UILabel {

does.

---

<div class="post-metadata">

**Author:** ![bdmoakley](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/bdmoakley/32/108772_2.png) [@bdmoakley](https://forums.kodeco.com/u/bdmoakley)\
**Post date:** [July 7, 2019, 9:48pm UTC](https://forums.kodeco.com/t/beginning-table-views-challenge-updating-the-controller-ray-wenderlich/47867/9 "2019-07-07T21:48:56Z")

</div>

Here’s the breakdown. What you are doing is getting a plain old UIView back from the method call, viewWithTag(1000). iOS will search for a view with a tag assigned as 1000. That view might not exist, so you use if-left binding.

That is, if a view is returned it will be populated in the label variable. The problem with viewWithTag is that it returns a regular UIView. You need to access a UILabel instead which is why you do a as? UILabel cast. If the view fails to cast to a label, then the code will skip over the code block.

I hope that helps!

---

<div class="post-metadata">

**Author:** ![hashmo](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/hashmo/32/81494_2.png) [@hashmo](https://forums.kodeco.com/u/hashmo)\
**Post date:** [October 22, 2019, 12:54pm UTC](https://forums.kodeco.com/t/beginning-table-views-challenge-updating-the-controller-ray-wenderlich/47867/10 "2019-10-22T12:54:29Z")

</div>

I agree. In the cellforrowat we could have used the checked value from the model to show/hide the checkmark instead of calling configureCheckmark (which ends up updating the model and reversing the checkmark). I think we’d also need to have initialised the todoList CheckListItems to all be checked = true for this to work as well as giving them some text.  
Then configureCheckmark only needs to be called from didselectrowat.

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [November 14, 2019, 7:40pm UTC](https://forums.kodeco.com/t/beginning-table-views-challenge-updating-the-controller-ray-wenderlich/47867/11 "2019-11-14T19:40:15Z")

</div>

@hashmo Thank you for sharing your solution - much appreciated! :]

---

<div class="post-metadata">

**Author:** ![brigden17](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/brigden17/32/81494_2.png) [@brigden17](https://forums.kodeco.com/u/brigden17)\
**Post date:** [July 18, 2020, 10:08am UTC](https://forums.kodeco.com/t/beginning-table-views-challenge-updating-the-controller-ray-wenderlich/47867/12 "2020-07-18T10:08:45Z")

</div>

Hi. Why do you initialise the TodoList in the viewcontroller init instead of just setting it at the variable definition `var todoList = TodoList()`?
