Question

In iOS before storyboards I used nibs and used the following code to present a UIViewControllers View. I am trying to figure out how to do this with storyboards. It is crashing when it calls initWithNib. I am open to all suggestions on how to fix this. Thank you in advance.

       folderCollectionView = [[FolderCollectionViewController alloc] initWithNibName:@"FolderCollectionViewController" bundle:nil];

        folderView = [folderCollectionView view];
        [folderView setFrame:CGRectMake([[self view] bounds].origin.x, [[self view] bounds].origin.y, [[self view] bounds].size.width, [[self view] bounds].size.height)];
        folderCollectionView.delegate = self;
        [[self view] insertSubview:folderView atIndex:1];
        [[self view] bringSubviewToFront:folderView];
        [folderView setBackgroundColor:[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.0f]];

        folderView.alpha = 0.0;
        [UIView animateWithDuration:1.2f
                              delay:0.0f
                            options: UIViewAnimationCurveEaseIn
                         animations:^{
                             folderView.alpha = 1.0;
                         }completion:nil];
Was it helpful?

Solution

Replace

   folderCollectionView = [[FolderCollectionViewController alloc] initWithNibName:@"FolderCollectionViewController" bundle:nil];

with

   folderCollectionView = [self.storyboard instantiateViewControllerWithIdentifier:@"FolderCollectionViewController" bundle:nil];

Make sure you set the identifier in interface builder

enter image description here

OTHER TIPS

With storyboards you usually aren't going to use the iniWithNib method. You do it by calling

[self performSegueWithIdentifier:@"segueIdentifier" sender:buttonName];

The identifier is set in the storyboard file after you control-drag from one view to another. then to configure the new view you implement

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    folderCollectionView = [segue destinationViewController];
    ...
    // Complete the rest of you view initialization here
}

You can read more about storyboards here: Apple's Storyboards

I had the same problem.

I did it like this:

AddsViewController *addsViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"AddsViewController"];
[self.navigationController pushViewController:addsViewController animated:YES];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top