TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

TableView didSelectRowAt save value to different properties.

Forums > Swift

Hello,

I need to choose element from table, then choose again second element from this same table view, then display them in another controller together in one table.

I try do this by the way of creating two variables of this same property, and distinguish, which is tapped, but I don't know how.

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        //let firstCurrency = [rates[indexPath.row]]
       // let secondCurrency = [rates[indexPath.row]]
        let firsCurrency = [rates[indexPath.row].pair.source.name]
        let secondCurrency = [rates[indexPath.row].pair.target.name]
        let vcRates = RatesViewController()
        let vcSelf = CurrencyViewController()

        if firsCurrency.contains(where: {$0.count == 1}) {
            vcSelf.modalPresentationStyle = .fullScreen

        } else {
        vcRates.modalPresentationStyle = .fullScreen
        }
        //vc.modalPresentationStyle = .fullScreen

    }

In here you can see "rates" property which is model from API.

And so on a little of my mess.

At the end my question is, how I can assign value from tableview to firstCurrency at the first time, then somehow assign value to the secondCurrency, at the second.

Thanks for help.

3      

I would solve this using the same tableView to allow the user to select the source and target rows. You could store the indexPath of each in a variable, and highlight the selected cells accordingly as a kind of toggle. Once you have a source and target you could then enable a 'Next' button to move to the next view, and pass through the two values.

3      

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.