I have a NavigationController which has a TableView in it. The cell in the TV has a "modal" segue which points to a TableViewController (Class: Details.h/.m). When I select the cell I get taken to the TableViewController as expected.
However I need to add the following functionality:
1) push to the destination so I get a nice back button.
2) pass various object information in the selected cell to the destination TVC.
To accomplish this I perform the following tasks:
1) Change the segue to "push" and give it an identifier "segueToDetails"
2.1) add code to the didSelectRowAtIndexPath method (below)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"segueToDetails" sender:self];
}
2.2) add code to the prepareForSegue method (below)
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
NSInteger rowNumber = selectedIndexPath.row;
myObject = (MyObject *) [myArray objectAtIndex:rowNumber];
Details *details = [segue destinationViewController];
details.detailsObject = myObject;
}
2.3) to confirm that the object information is being passed to the destination I output some data using NSLog (below)
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"name: %@", detailsObject.name);
}
Now when I run the project and select a cell in the table I get brought to the destination TVC, I see the output from NSLog which is good. I also have a nice back button. But wait, when I click back, I have another back button! Clicking that back button then returns me to where I originally came from. The debugger window shows this message every time I segue to the destination TVC.
2012-01-24 13:55:58.240 MyApp[26875:11603] nested push animation can result in corrupted navigation bar
012-01-24 13:55:58.593 MyApp[26875:11603] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
2012-01-24 13:55:58.593 MyApp[26875:11603] Unbalanced calls to begin/end appearance transitions for <SpotDetails: 0x7a7a370>.
Any suggestions on how to resolve this?
PS - I'm using Xcode 4.2 w/ ARC, iOS 5
You are pushing the view twice; once in the storyboard and once in didSelectRowAtIndexPath. When you wire up the segue in the storyboard do not link it to the table cell directly but rather to the view controller so that you can perform the segue programmatically instead of the storyboard doing this for you when you press the cell.
If you have a modal segue in the storyboard, you don't need the code in the didSelectRowAtIndexPath:. The storyboard will do all the rest. If you try to do the segue manually and also have it in the storyboard you will have problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With