Beginning Table Views · Swipe to Delete | Ray Wenderlich


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

Hi Brian,

I’ve been working throw your ‘Beginning Table Views’ class and I’m really learning a lot. Thanks for that!

I have a question on the ‘Swipe to Delete’ video.

In this video, you showed us how to enable the swipe-to-delete feature and then how to delete the selected data from the model (the ToDoList array).

Then you showed us two ways that we can remove the deleted row from the tableView. We can either use the tableView.deleteRows method or we can just reload the data using tableView.reloadData().

But, when I use the reload method, checkmarks appear on all of the remaining to do items in the list. I noticed that that happened to you too when you demonstrated it on the video.

Why is that happening? Why are checkmarks appearing on previously unchecked items when all we are doing is reloading the data? I don’t think we’re changing the data for those other rows, so how does the checkmark get flipped on?

I’ve looked pretty carefully through the coding and I can’t see why this is happening. Can you help?

Thanks,

Mary

Hi Mary,

I looked through the code and saw there was a slight bug in there. Basically, each time we reload the data, the method, configureCheckmark is being called by each cell. This method sets the state of each cell per the model. At the bottom of the method, it checks the checkmark. That toggle method should be outside of the configureCheckmark. That’s why you are seeing the strange behavior.

I’ll make a note of this and make sure we correct this in the next iteration, or I’ll add a small update to fix it as well. Thanks for letting me know!

Thanks, Brian…I found it too!

Thanks again!

Mary

Hi @bdmoakley , I wanna try adding the green plus button at the end of the vid. You mentioned we need to override editingStyleForRowAt and return a .insert . Then handle both .insert and .delete in commit. However, nothing seems to show in my simulator. Can you share how you did it ? Thank you :slight_smile:

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

Make sure that the table is se to editing mode. Once set, you should see the green plus signs. Try it out and let me know what you find. :slight_smile:

oh yeah… after enabling the edit button i see it now… thanks Brian! :slight_smile:

1 Like

When changing the constraints for the Label in the storyboard if I follow your instructions (750 and 750) I get an Auto Layout red error.
I changed one of the two to 751 to fix this but I have no idea why that worked.
Xcode proposed me to add the missing constraints but I refused :slight_smile:

Thank you

Also found this bug! basically move the toggleChecked() call to the didSelectRowAt func and it’ll solve it so that you seperate the toggling of the checkmark with the displaying of it and don’t have them all in one function!

Thank you for sharing your solution - much appreciated!

Some friendly feedback: Considering that the course is supposed to be catering to beginners, I found the explanation regarding the plus buttons at the end of the video to be somewhat skimpy and not matching the pace of the rest of the course.

I tried to figure it out by myself, please correct me if I’m wrong:
You first need to add another BarButton, change its configuration to “Edit”, link up the button with the ViewController and within the new IBAction’s body call the tableview.setEditing method.
Also you need to configure the (:editingStyleForRowAt:) method so that it returns the .insert editing style if the user is editing (tableView.isEditing = true) and the .delete style otherwise. Lastly you need to change the (:commit:forRowAt:) method so that it can distinguish between both editing styles and behave accordingly.

@bdmoakley Do you have any feedback about this? Thank you - much appreciated! :]