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

有帮助吗?

解决方案

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.

其他提示

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.

Did you override viewWillAppear/viewDidAppear/viewWillDisappear/viewDidDisappear? Did you remember to call super from your override?

I had segues that were leading back to my main navigation controller which was causing this. I fixed the problem by setting the main navigation controller back to the top of the stack. Here is the code:

- (void) viewDidAppear:(BOOL)animated
{
    [self.navigationController popToRootViewControllerAnimated:NO];
}

Just want to add my solution to my problem to this thread in case anyone have the same issue as i had.

I copied a button and then connected it. It worked but i did get this error.

It turned out i had missed too cancel the old connection on the copied "new" button so i had two connections, the new and the old. Just deleted the old and it worked.

I faced this problem, when i have pushed to next viewController twice accidentally. This happened, when i forgot to remove a push segue i was using for testing. So before anything else check the silly mistake whether you have pushed it twice manually

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top