UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

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.