I am developing an app using Xcode in Swift. Briefly I have a tableViewController that houses many cells. There is a button in every cell (A stepper to be exact). My question is, how can I get the index of the cell which houses the stepper every time I click on it (the stepper)?
*Bonus point for knowing if the user pressed the 'Minus' or 'Plus' side of the stepper.
I search a very long time and I am still not sure how to approach this situation, nothing I try seems to be working.
Some context:
My tableViewController looks like this. enter image description here
Every cell has a few labels which are populated with informations taken from a file that I import. When importing the file I store all of its information in an array which I read every time I populate the tableView. Along with that, I have a label that will increment or decrement using the stepper. This allows me to track how much of which item I need to order. In the end, what I want to do is update my array with the amount I want to order so that it is saved for the next time I quit and reopen the app.
I have two ways that I think might work,
1: use the stepper to trigger a function that will increment or decrement the value for the order of its own cell using the index value for the cell in which the stepper is located.
2: Have the stepper only change the orderLabel, then have a save button that will go through every tableCell and read the orderLabel to save it into the array using the indexValue.
I don't know which would be the best way but I feel like the reading and the saving of the oderLabel to the array has to happen in my ItemTableViewController, as that is where I created the array which stores all my data.
Thanks, and I hope this will help.