Hi There im creating an app using table views in storyboards and so far i am able to populate the table i have it set to making 4 cells and push to the same view controller from each cell but what i want to be able to do is each cell takes me to a new view controller
Here is what i have so far if you could point me in the right direction in to how to be able to do this would be great
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"ShowSimpleDetails"]) {
SimpleTutorialsViewController *detailViewController = [segue destinationViewController];
NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];
int row = [myIndexPath row];
detailViewController.simpleDetailModal = @[_simpleTitle[row], _simpleDescription[row], _simpleImages[row]];
}
}
You can do it in the storyboard or in code:
In Storyboard
You can draw a segue from a cell to a destination view controller and give that segue a unique identifier in the property inspector. You can use this to segue to multiple destinations by having multiple cell prototypes, with each prototype having its own segue.
In Code
To do it in code, you would draw a segue from your view controller (not the cell) to each destination and give each segue a unique identifier. Then in didSelectRowAtIndexPath
, you would decide which destination you want based on the selected index path and perform the segue like
NSString *segueIdentifier = @"someIdentifier";//or whatever logic you need to determined the appropriate identifier
id sender = self;//or whatever object you want to be the sender
[self performSegueWithIdentifier:segueIdentifier sender:sender];
prepareForSegue
In prepareForSegue
, you'd have a conditional block for each possible segue identifier:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"oneSegueIdentifier"]) {
//preparation
} else if ([[segue identifier] isEqualToString:@"anotherSegueIdentifier"]) {
//other preparation
}
}