Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
I have two view controllers. One contains a menu, and the other contains a submenu. If the user taps the "back" button on the submenu's controller, then the controller needs to pass data back to the original menu.

Since both view controllers are linked to a navigation controller, I'm thinking of doing something like this:

Code:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UINavigationController *navController = [self navigationController];
NSArray *viewControllers = [navController viewControllers];
NSInteger destVCIndex = [viewControllers indexOfObject:[segue destinationViewController]];
NSInteger selfIndex = [viewControllers indexOfObject:self];
if (destVCIndex == selfIndex - 2)
{
// Destination view controller was loaded before this one.
}
}
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,560
6,059
Wouldn't you want just - 1, not - 2?

I haven't done anything like this, but I thought there was something called a Segue Unwind or something like that that gets called when a back button is pressed?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.