2

I have an app with two View Controllers. The first one is embedded in a Navigation Controller and has a navigation bar, I present the second View Controller programatically after a certain method has ended in the first View Controller. This works fine, but this way the second View Controller is not part of the Navigation Controller stack and does not really have any relationship with the first View Controller. Like this, I can't take advantage of the Navigation Controller. Any thoughts on how could I solve this?

I present the second view controller with this code after the user has picked an image from the photo library:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
  pickedImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
  [self dismissViewControllerAnimated:YES completion:NULL];
  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
  ViewController *viewController = (ViewController *)[storyboard instantiateViewControllerWithIdentifier:@"viewControllerID"];
  viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  [self presentViewController:viewController animated:YES completion:nil];
}
3
  • Why are you can't use pushViewController:animated:? Commented Apr 28, 2015 at 14:14
  • how do you present the second view controller?? show some code Commented Apr 28, 2015 at 14:24
  • You need to start with this article developer.apple.com/library/ios/documentation/WindowsViews/… Commented Apr 28, 2015 at 14:31

2 Answers 2

1

instead of the

[self presentViewController:viewController animated:YES completion:nil];

use

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

So that the VC2 is also in the same Navigation stack

Your final code looks like this:

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
    ViewController *viewController = (ViewController *)[storyboard instantiateViewControllerWithIdentifier:@"viewControllerID"];    
    viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self.navigationController pushViewController:viewController animated:YES];
}
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

YourController *controller = [[YourController alloc] init];

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

4 Comments

Thanks! I tried this but all I get is a black view. What could be the problem?
Ok so I present the second view controller after the user has picked an image: -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; ViewController *viewController = (ViewController *)[storyboard instantiateViewControllerWithIdentifier:@"viewControllerID"]; viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; [self presentViewController:viewController animated:YES completion:nil]; }
Change modal to push. I think that is the problem.
Thanks, I tried but did not work :(. I edited my oq so it's a bit more clear maybe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.