john doe
john doe

Reputation: 9660

UITableView Cells Segues to Different Controllers

I am using a dynamic UITableView control to display a menu. The menu can change based on certain conditions. Now, I want that when I click on the menu item it takes me to a different controller.

How can I accomplish this without having to create multiple segues in Storyboard? I have 9-10 options that display in the UITableView and I really don't want to create 9-10 different segues in the storyboards.

Upvotes: 0

Views: 33

Answers (1)

Aleš Kocur
Aleš Kocur

Reputation: 1908

You can always load controllers programmatically. Set Storyboard ID for your controllers as shown on image:

Storyboard ID setup

Then if you have only one storyboard, you can load load controller like this:

if let controller = self.storyboard?.instantiateViewControllerWithIdentifier("SettingsViewController") {
    self.navigationController?.pushViewController(controller, animated: true)
}

If you have multiple storyboards, you should use:

let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("SettingsViewController")
self.navigationController?.pushViewController(controller, animated: true)

Upvotes: 1

Related Questions