Вопрос

I am making an iOS app where the user starts in the main menu (see figure).

When the user clicks button1, it triggers a segue (1) that takes him to a configuration wizard. On the other hand, clicking button2 takes the user to a configuration listing (showing what is already set), this also using a segue (2). Both these view controllers have a back button, that takes the user back to the main menu by calling

[self dismissViewControllerAnimated:YES completion:nil];

What I'm now struggling to implement, is a way to make the transition from the configuration wizard to the configuration listing.

When the user has made his choices in the wizard, and pushes the save button, I want this to take him directly to the configuration listing view. At the same time, the wizard view controller should be "forgotten", that is when the user now pushes the back button2, it should still take him back to the main menu. This means that I cannot just trigger a segue to the listing from the wizard, since then the wizard would still be there, "behind" the listing view, and would become visible when back button2 was pressed.

Any ideas on how to smoothly implement this? storyboard

Это было полезно?

Решение 2

At Configuration Wizard screen, use presses save

[self.navigationController pushViewController:listOfConfigurationViewController animated:YES];

At this time, your stack is :

 Main View Screen -> Configuration Wizard Screen -> List Of Configuration Screen

When uses presses back button at List Of Configuration Screen

// you will come back to Main Screen View
[self.navigationController popToRootViewControllerAnimated:YES];

Другие советы

You can add a segue from Configuration Wizard to List of Configurations. To avoid going back to Configuration Wizard store the Main Menu ViewController pointer and say popToViewController API for navigation.

Code sample where popToViewController is being used.

NSArray * controllerArray = [[self navigationController] viewControllers];

for (UIViewController *controller in controllerArray){
    //Code here.. e.g. print their titles to see the array setup;
    //NSLog(@"%@",controller.title);
    if ([controller.title isEqual:@"ViewTitle"]) {
        [self.navigationController popToViewController:controller animated:YES];
    }
}

Hope this helps.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top