Search code examples
iphoneios5xibnibstoryboard

Xib Vs Storyboard, how to update


I was studying Storyboard on the new iOS 5.0. It seems really simple to use and to implement but my question is ... How can I update the old Xib to Storyboard?

For instance. I have some classes I developed when there was no storyboard and some of this classes come with xib file that help me to setup a custom layout quickly. Obviously when I use this kind of class I need to instantiate it using initWithNibName:bundle: and it now is ready to use and I can use it as many times I need because layout is coded inside xib.

Now Storyboard ... Storyboard doesn't allow to load view controller from xib and I did not found a way to load storyboard file inside the main storyboard. It seems like I need to reconfigure layout for a particular view controller every time I use it in a new project. It seems that now I'm forced to reconfigure the layout of my controller in every new application that use this controller instead of using xib file that have the layout inside.

Maybe there is something I did not understand. Anyone can help me to understand the best way to use storyboard?

Thank you in advance.

Gabriele.

EDIT in reply to sw3n

Maybe I understood thanks to sw3n. This code below works but is this completely correct?

// All this code is implemented inside the MyViewController class.

// Attached to an UIButton;
- (void)loadNewController:(id)sender {
    [self performSegueWithIdentifier:@"newControllerIdentifier" sender:sender];
}

- (void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender {
    // As suggested by sw3n
    // Load the storyboard from file.
    UIStoryboard *storyboardTest = [UIStoryboard storyboardWithName:@"StoryBoardLoad_Test" bundle:nil];
    // Instantiate the viewController that live in the storyboard file
    UIViewController *destinationViewController = [storyboardTest instantiateViewControllerWithIdentifier:@"newControllerIdentifier"];
    
    // Instantiate a segue to start the chain
    UIStoryboardSegue *segue = [[UIStoryboardSegue alloc] initWithIdentifier:identifier source:self destination:destinationViewController];
    [self prepareForSegue:segue sender:sender];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"newControllerIdentifier"]) {
        [segue.destinationViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
        
        // Are there new options to present the controller?
        // If I was in a NavigationController a could obviously push it.
        [self presentModalViewController:segue.destinationViewController animated:YES];
    }
}

Solution

  • Is this what you're looking for?

    (UIStoryboard *)storyboardWithName:(NSString *)name bundle:(NSBundle *)storyboardBundleOrNil