My root controller is a TableViewController with static cells and a navigation controller. Depending on which cell is selected I want to push another ViewController (with an embedded TableView) that will change its configuration accordingly (buttons enabled or not, cells data from a db table or an NSArray, etc.). Selecting some "Controller A" cells will call the "Controller B" or "Controller C" and pass some data.
The code I'm trying looks like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
switch (indexPath.row) {
case 0:
{
[self performSegueWithIdentifier:@"segueToType" sender:self];
}
break;
case 1:
{
[self performSegueWithIdentifier:@"segueToType" sender:self];
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"segueToType"])
{
NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
NSInteger rowNumber = selectedIndexPath.row;
switch (rowNumber) {
case 0:
{
TypeSelectController *selCon = [segue destinationViewController];
selCon.myPet = self.myPet;
selCon.sel = @"tipo";
selCon.delegate = self;
}
break;
case 1:
{
TypeSelectController *selCon = [segue destinationViewController];
selCon.myPet = self.myPet;
selCon.sel = @"razza";
selCon.delegate = self;
}
break;
default:
break;
}
}
}
In this case, for example, I'm calling only the "Controller B", but depending on the selected cell of "Controller A", it configures itself in different ways (depending on "selCon.sel" string).
In the "Controller B", I have this kind of code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([sel isEqualToString:@"tipo"]) {
NSString *itemToPassBack = [tipi objectAtIndex:indexPath.row];
[self.delegate addItemViewController:self didFinishEnteringItem:itemToPassBack ofType:@"tipo"];
[self.navigationController popViewControllerAnimated:YES];
} else if ([sel isEqualToString:@"razza"]) {
NSString *itemToPassBack = [razze objectAtIndex:indexPath.row];
[self.delegate addItemViewController:self didFinishEnteringItem:itemToPassBack ofType:@"razza"];
[self.navigationController popViewControllerAnimated:YES];
}
}
So again, depending on the string "sel" value, I'm returning different data to "Controller A".
When I select the first cell in Controller A, I correctly get the Controller B scene. Then I select a cell and go back to Controller A with correct data. Now if I try to select the second cell in Controller A and select a cell in Controller B, the navigation do not respond as I want to and I get the Controller C scene, then the Controller A and the following errors:
nested push animation can result in corrupted navigation bar
Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
Unbalanced calls to begin/end appearance transitions for .
What am I doing wrong?