Beginning Table Views · Fixing Checkmarks | Ray Wenderlich

This is a companion discussion topic for the original entry at

Brian, @bdmoakley

I think I am completely lost in this section.
My questions are the following:

  1. Why exactly did you create ‘configureCheckmark’ and copied and pasted all the code that was under override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) ??

And not exactly solving the checkmark bug?

Could you please expand the purpose of configureCheckmark function? What exactly are you configuring? and Why did you copy and paste the if statements above??

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

I agree I’m confused too. The didSelectRowAt contained the code to toggle the checkmark. Initially this was done based on whether the checkmark was currently shown in the cell or not. Then we updated this code to also then use/update our model object. Then we wrapped all this code into configureCheckmark and then also called it from the cellForRowAt method. We were getting problems in that cellForRowAt method because when it scrolled and re-used the cell it remembered the state of the checkmark from the cell it was re-using rather than the checkmark being shown based on the model’s value.
What’s confusing is that configureCheckmark is now reading AND updating the model. I get why you would want to read & update the model during a didSelectRowAt. But I can’t figure out why you’d want to update the model in a cellForRowAt.

@hashmo Do you still have issues with this?

Thanks for getting back to me. No, it’s fine. In a later tutorial the presenter changes this and restricts cellForRowAt to just read the model instead of also updating it.