问题
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!
回答1:
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.

Drag and drop a segue from that button onto the View Controller that you want to connect.
Hope this helps.
回答2:
This was extremely helpful and what I needed to do to get rid of the segue from the table view cell. Doing exactly what you suggested above and adding this to the tableViewDidSelectRowAtIndexPath...
override func tableView(tableView: UITableView,didSelectRowAtIndexPath indexPath: NSIndexPath)
{
if let indexPath = self.tableView.indexPathForSelectedRow
{
rowSelected = indexPath.row
sectionSelected = indexPath.section
//Transition to the Set Details VC
if indexPath.section == 0
{
print("Set Details")
self.performSegueWithIdentifier("Segue1", sender: self)
}
//Transition to the Info Section
else if indexPath.row == 0 && indexPath.section == 2
{
print("About Page")
self.performSegueWithIdentifier("Segue2", sender: self)
}
}//End If IndexPath
}//End DSRAIP
来源:https://stackoverflow.com/questions/24318781/how-do-i-make-multiple-tableview-cells-to-lead-corresponding-view-controllers