Check to see if back button was pressed

Discussion in 'iOS Programming' started by moonman239, Jul 11, 2014.

  1. moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #1
    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.
    }
    }
    
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    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?
     

Share This Page