In short how to call performforsegue method inside didselect row for indexpath. I have an array and this array is the contents of tableView
`let array = ["USD","Inr", "AUD", "AED"]`
and I have values for this array
let valueUSD = "65"
let valueInr = "10"
let valueAUD = "70"
let valueAED = "20"
I have another viewController with an optional string and a label and on the viewdidload I called
label.text = optionalstring //just a pseudocode but you get the idea
Now comes the problem, when the user selects USD I want the optionalstring to take the value of valueUSD variable and when he selects INR it should take valueInr variables value so on , so that the destination view controller will display this value, I don't know how to achieve this, how to gethold of selected indexpath.row and based on that how to set the value, for example
if indexpath.row == 0
`destinationViewController.optionalString = valueUSD`
I appreciate your attention.
You should store your data in an array of your custom struct type:
where
MyData
is like this:You'd probably need to change your
cellForRowAt
method to set the cell's label text toarray[indexPath.row].name
rather thanarray[indexPath.row]
.In
didSelectRowAt
:And then, override
prepare(for:sender:)
: