BDGapps
BDGapps

Reputation: 3356

Present UIViewControllers View Storyboards

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];

Upvotes: 1

Views: 812

Answers (3)

Abdullah Umer
Abdullah Umer

Reputation: 4624

I had the same problem.

I did it like this:

AddsViewController *addsViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"AddsViewController"];
[self.navigationController pushViewController:addsViewController animated:YES];

Upvotes: 0

endy
endy

Reputation: 3872

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

Upvotes: 1

MikeCocoa
MikeCocoa

Reputation: 296

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

Upvotes: 0

Related Questions