ChrisK
ChrisK

Reputation: 57

Transitioning from uitableview to new viewcontroller

I'm working on the "settings" portion of my app. When one of the cells is clicked, I need to transition to a new View Controller depending on which cell was clicked.

I have found a ton of answers, but they all seem to not go far enough. I understand how to set up a segue to a new view controller and I understand how to use didSelectRowAt Indexpath to show which cell was clicked. I can figure out the transition, but I can't figure out many different transitions based on which cell was clicked.

Is there a way to do this with dynamic cells or should I be using static?

Upvotes: 2

Views: 64

Answers (1)

SwiftGod
SwiftGod

Reputation: 386

If you have fixed amount of cells, I'd go for static cells. However if you want to use dynamic cells, you can create something like enum with cases that store row index.

    fileprivate enum Row: Int {
        case volume = 0
        case notification = 1
    }

Then in didSelectRowAt delegate method:

    let row = Row(rawValue: indexPath.row)!
    switch row {
    case .volume:
         // Navigate somewhere
    case .notification:
         // Navigate somewhere
    }

Upvotes: 1

Related Questions