Life Life - 10 months ago 50
Swift Question

Swift - Table View Cell Button to perform actions and then reload TableView

I am making a simple to-do list app using CoreData. I currently have the functionality of adding new list-items, editing them, and deleting them using swipe finished. Now, however, I want to add functionality to a button I have in each cell to delete the cell AND create a new entity in a different CoreData file (don't know what to call the list of different entities. Basically I have "todo" and "completed". I want to delete from todo and make new entity in completed).

In my custom cell class I have the connection for my button printing "pressed" as well as printing the sender object. My button(s) properly reacts to being pressed, but I don't know how to:

send the indexPath information to the cell so the buttonPressed action knows what to delete from CoreData

and second:
reload my tableView on my main viewcontroller file when the button is pressed.



The easiest way to do this would be to create a property for a callback on the table view cell. In the cellForRowAtIndexPath(_:) method, give the cell a callback that reloads the table view. When the IBAction is fired on the cell from tapping the button, simply invoke the callback that was given.