I\'m creating an app in ios5 using storyboards. I have a tableviewcontroller embedded in a navigation controller and when you click on the cells in the tableviewcontroller s
Don't need Call:
[self performSegueWithIdentifier:@"mySegueId" sender:self];
you could use NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
to get your selected info, in your - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{...}
function.
I was having the same problem (from lack of experience with iOS5).
It turns out that is an example app with the iOS5 SDK which has a table view that uses segues when a table cell is tapped : "Simple Drill Down".
https://web.archive.org/web/20130513140140/http://developer.apple.com:80/library/ios/#samplecode/SimpleDrillDown/Introduction/Intro.html
You do set the segue at the table cell and give it a name in the storyboard file.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
/*
When a row is selected, the segue creates the detail view controller as the destination.
Set the detail view controller's detail item to the item associated with the selected row.
*/
if ([[segue identifier] isEqualToString:@"ShowSelectedPlay"]) {
NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
DetailViewController *detailViewController = [segue destinationViewController];
detailViewController.play = [dataController objectInListAtIndex:selectedRowIndex.row];
}
}
I got the same problem and haven't solved it yet with storyboards. However, I think that the segue should start at the cell, not the entire tableviewcontroller. if you use prototype cells, this could work - but i don't know about code-created cell types. would appreciate any help on this topic, too.
Edit: The tutorial at http://kurrytran.blogspot.com/2011/10/ios-5-storyboard-and.html suggests that no segue solution exists and you still have to do the transition to detail view in code. I don't know how correct this is, but I will just do it that way until someone shows me the pure storyboarding/segue solution ;).
I got the same problem, Followed parts of Ray Wenderlich tutorial and found that you need to select table cell and Ctrl-Drag to your viewcontroller. Then call performSegueWithIdentifier
in didSelectRowAtINdexPath
.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"mySegueId" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSLog(@"prepareForSegue: %@", segue.identifier );
if ([segue.identifier isEqualToString:@"mySegueId"])
{
DetailController *detailController = segue.destinationViewController;
detailController.delegate = (id)self;
detailController.selected = selectedRow;
}
}
Try this way
First Name Your segue(from tableview cell to detail view).Then
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"yourSegueName"]){
DetailViewController * detailViewController =segue.destinationViewController;
detailViewController =[self.yourTableViewDataArray objectAtIndex:[self.yourTableView indexPathForSelectedRow].row];
}
}
Don't forget to import your SecondViewController/DetailViewController