In a table of several sections, when removing checkmarkers installed in cells, I delete the elements of the pressed cell from the array.

removeAtIndex(indexPath.row) works erratically, and then only after repeatedly removing checkmarkers from a large number of pressed cells, the application drops, then after the first removal. I can not fully understand how to correctly specify in the removeAtIndex index of the pressed cell. On the screen, for example, the application fell only when removing the checkmarker from the last clicked cell (elements of the same cell remained in the array)

enter image description here

  • Delete code can be viewed - Max Mikheyenko
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky
  • Hello. The question has already been answered, so it is undesirable to delete it - this will lead to a loss of effort invested by another participant. I formatted the question a little to make it better read. - Nick Volynkin
  • If necessary, you can untie the question from your account, but this is an extreme measure. Waiting for an answer. - Nick Volynkin
  • Thank you, then let it remain ... - Artur Skachkov

2 answers 2

You have a loaded table, say, with 10 elements (10 elements in the array), when you write exercise.removeAtIndex(indexPath.row) , then you give the command to remove the element from the array, but the same element is used to display in the table - this time problem. Another may occur when the first call to you in numberOfRowsInSection 10, and the array now has 9 elements, hence in the cellFor... method cellFor... you are out of range of the array.

Solutions:

    You can also save the status highlighted / unchecked for each item (instead of deleting) Then you select only selected elements from the array and use them for their intended purpose.