Question

My project is in iOS6.I have three UIViewControllers on my iPhone storyboard. On the first UIVC i have a checkbox and a continue button. If checkbox is checked and button is clicked then I have to launch second UIViewController.If checkbox is unchecked and button is clicked launch the third UiViewController. How do i do it? I have done this so far:

- (IBAction)btnContinue:(UIButton *)sender
{
if (self.shipToDifferentAddress)//Checkbox CLICKED->YES
{
    //Launch ShippingVC
    ITMShippingAddressVC *shippingVC = [[ITMShippingAddressVC alloc]init];
    [[self navigationController]pushViewController:shippingVC animated:YES];
}
else //Checkbox unchecked ->NO
{
    //Launch OrderedItemsVC
    ITMOrderedItemsVC *orderedVC = [[ITMOrderedItemsVC alloc]init];
    [[self navigationController]pushViewController:orderedVC animated:YES];
}
}

The self.shipToDifferentAddress is a bool variable telling launch this or that. I logged both the viewDidLoads and i got the output from both of them.There is some content on both the second and third UIViewControllers like buttons, labels etc. But they appear black.No content. I have back buttons on both of them and I can traverse back to first UIVC from either one of the one. SO what am i missing? I used segues incases where I had to go to a specific UIVC. Now i have a choice either second or third. How should i do it?Please let me know if you need more information. Thanks.

Was it helpful?

Solution

To present your ViewControllers that are in your storyboard, follow this:

    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard"
                                                             bundle: nil];
    ITMShippingAddressVC *viewController = (ITMShippingAddressVC*)[mainStoryboard
                                                                         instantiateViewControllerWithIdentifier: @"ITMShippingAddressVC"];

Set the Identifier in your storyboard.. click on your view, and in the right properties menu set the Storyboard ID enter image description here

Than you can push like normal:

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

While this will work for you-- when using Storyboards, ideally you want to use Segues. It requires much less code. Here is a good tutorial on using segues to push/present view controllers and pass data between them.

OTHER TIPS

You have created your VC's, but they are not linked to the storyboard ITMOrderedItemsVC and ITMShippingAddressVC. So the interface that you added in storyboard doesn't get loaded.

What you could do is create a separate xib file for each of your VCs (New > file... > User Interface > View). Name the xib file the same as your viewController:

ITMOrderedItemsVC.xib
ITMShippingAddressVC.xib

Design your interfaces in these xib files (they are just like single-entity storyboards).

The xibs will be automatically loaded when you init an instance of the respective viewController.

This will work with your current code.

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