Question

I'm not sure why but in Xcode 5 working on a project of IOS6.1 I have a button connected to a IBAction in which I'm trying to navigate to a new view controller.

I've tried two different codes to create the viewController and then push it to the navigation in both cases the view controller is not nil and both cases the viewController doesn't appear.

first try: with story Id - I've set the story id of the view controller to imageCapture and set the class to VSImageCaptureViewController

VSImageCaptureViewController* imageCaptureViewController = (VSImageCaptureViewController*)([self.storyboard instantiateViewControllerWithIdentifier:@"imageCapture"]);

[self presentViewController:imageCaptureViewController animated:NO completion:nil];

second try: with the name of the viewcontroller

VSImageCaptureViewController *imageCaptureViewController = [[VSImageCaptureViewController alloc] initWithNibName:@"VSImageCaptureViewController" bundle:nil];

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

can you see something wrong or do you think I forgot to initialize something

Was it helpful?

Solution

Check to see if self.navigationController is nil.

If it is nil that means that you are not running within the context of a UINavigationController (the system sets this property for you when the UIViewController is added to a nav stack).

If this is the case then you have not properly set up a UINavigationController.

Note that you can not set the navigationController property yourself. The systems sets it for you when the UIViewController is added to a UINavigationController's stack (and sets it to nil when it is removed from the stack).

To set this up you will usually create a UINavigationController instance right after you create your main view controller.

UIViewController *mainViewController = ...;
UINavigationController *mainNavController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
// now present the mainNavController instead of the mainViewController

If you are using storyboards you would drag out a UINavigationController instance and replace the default root view controller with an instance of your mainViewController.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top