2
votes

Here is my problem (See illustration bellow):

I have a main screen (MainViewController) from which i present a form modal (ModalController) embedded in a Navigation controller.

After completing the form I want to present the result to the user and dismiss the modal.

The result is shown with a ItemViewController and it should be pushed on the main stack, i.e. in a navigation controller and if the user presses back, he returns to the main screen.

My problem is how to dismiss the modal and push the new view controller at the same time?

Problem description

What I tried:

  • dismiss the modal and push the new view controller in the completion block using self.parentViewController.navigationController pushViewController:itemViewController but only the modal is dismissed.

  • push the view controller the same way then dismiss, also without effect.

  • unwind the modal to the main screen and from the unwindSegue method, instantiate and push the new view controller. Unfortunately, the code below has the same effect..


- (IBAction)unwindSegue:(UIStoryboardSegue *)segue {

    ItemViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ItemViewController"];

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

}

Might be important In the storyboard, ItemViewController is embedded in a NavigationController since it is defined as on the picture below:

enter image description here

1

1 Answers

2
votes

Maybe this can help:

in viewDidLoad method of ItemViewController:

UIImage *backButtonImage = [UIImage imageNamed:@"back.png"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];

[backButton setImage:backButtonImage
            forState:UIControlStateNormal];

backButton.frame = CGRectMake(0, 0, 55, 45);

[backButton addTarget:self
               action:@selector(goHome)
     forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = backBarButtonItem;

- (void)goHome{


NSArray *array = [self.navigationController viewControllers];

[self.navigationController popToViewController:[array objectAtIndex:0] animated:YES];


}