Olivia
Olivia

Reputation: 1

How do I make my table view's cell selection based on a stepper value, not the physical selection of the cell in swift 3?

How do I make my table view's cell selection based on a stepper value, not the physical selection of the cell in swift 3?

I want to transfer data to another view controller from a table view. I have this transfer occurring based on a segue right now. Currently my code takes the selected cell's information and passes it into the next view controller's label as it is supposed to through the function tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath). I now want the identification of what is to be sent to be based on the value that is read in the label connected to the stepper in the cell, not the physical selection of the cell. In other words how do I equate the selection of the cell to having a value greater than 0 inside the label inside the cell.

Upvotes: 0

Views: 160

Answers (1)

Jacob Boyd
Jacob Boyd

Reputation: 690

If I am understanding your question correctly, you are wanting to control the data passed, based on the value of your stepper, no matter which tableViewCell is selected?

If so inside of your segue:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if (segue.identifer == "(your segue ID)") {
        let vc = segue.destination
        vc.dataSource = tableViewDataSource[stepperValue]
    }
}

or:

let vc = yourDestinationViewController
vc.dataSource = tableViewDataSource[stepperValue]
self.present(vc, animated: true)

keep in mind this is pseudocode because I don't know what kind of objects you are using but I hope this helps to point you in the right direction. If you are grabbing the stepper value as a string, you will need to cast it to a Int.

Upvotes: 0

Related Questions