Steve Sahayadarlin Steve Sahayadarlin - 1 year ago 82
Objective-C Question

How do I make multiple tableview cells to lead corresponding view controllers?

I am making an app with a tableViewController as the initial view controller. It obviously has a list of items in tableview cells. I want each of the tableView cell to lead to a different View controller. Here is an example of my home screen:
![enter image description here][1]

What I am trying to achieve, for example, is that the tools cell will take me to a View controller with details about tools. And when I click on weapons, it should take me to a view controller with details about weapons. I already have the view controllers set up, but I don't know how to create segues to each view controller. NOTE: I made these cells in code and not in my storyboard. I made an array of items and I used indexpath.row to display them.

Thanks for any help!

Answer Source

nstead of connecting and creating segue from individual cells, you can connect all those segues from the View Controller button, lying below your view in your storyboard. In this case, you will have multiple segues and none of them will be individually connected to cells. And when segues are ready, you can use this method for moving on to the next View Controller depending on which cell is tapped from the tableView.

[self performSegueWithIdentifier:@"yourSegue" sender:nil];

You just have to check which cell is tapped and then perform the appropriate Segue on tap.

Look out for the yellow button as shown below your View Screen in your storyboard.

enter image description here

Drag and drop a segue from that button onto the View Controller that you want to connect.

Hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download