How to add a ViewDeck into a StoryBoard scene

Posted by – April 3, 2012

ViewDeck (https://github.com/Inferis/ViewDeck) is an amazing library that helps you to easily add a Facebook like menu into your application, unfortunelly it has a small issue with storyboards causing to not load the IIViewDeckController code properly.

In order to make use of ViewDeck in a specific scene of my storyboard, I created a blank scene with a empty view, in viewDidLoad method I added the following lines of code:

1
2
3
4
5
6
7
8
9
10
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
   
CenterViewController *centerController = (CenterViewController *)[storyboard instantiateViewControllerWithIdentifier:@"CenterViewController"];  

RightViewController *rightController = (RightViewController *)[storyboard instantiateViewControllerWithIdentifier:@"RightViewController"];  
 
self.containerController = [[IIViewDeckController alloc] initWithCenterViewController:centerController leftViewController:rightController rightViewController:rightController];
self.containerController.view.frame = self.view.bounds;
 
[self.view addSubview:self.containerController.view];

But this isn’t enough to get ViewDeck working, since I’m adding IIViewDeckController as child view of scene controller view, the viewWillAppear of IIViewDeckController doesn’t get called, which causes to not load ViewDeck on screen as it should be, hopefully you can fix it by calling viewWillAppear manually when viewWillAppear of scene controller is fired, like below:

1
2
3
4
5
6
- (void)viewWillAppear:(BOOL)animated {
 
  [super viewWillAppear:animated];
 
  [self.containerController viewWillAppear:YES];
}

After this small change you will be ready to use ViewDeck in you storyboard based projects!

Share

8 Comments on How to add a ViewDeck into a StoryBoard scene

  1. Darius says:

    Could you serve little demo somewhere? :)

  2. brandon says:

    This is a terrible idea…

    Try this instead:

    -(id)initWithCoder:(NSCoder *)aDecoder{

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

    menuController = (MenuViewController*)[storyboard instantiateViewControllerWithIdentifier:@"MenuViewController"];
    mainController = (MainViewController*)[storyboard instantiateViewControllerWithIdentifier:@"MainViewController"];
    friendsController = (FriendsViewController*)[storyboard instantiateViewControllerWithIdentifier:@"FriendsViewController"];
    self = [super initWithCenterViewController:mainController leftViewController:menuController rightViewController:friendsController];
    if (self) {
    NSLog(@”self initWithCoder”);

    }
    return self;
    }

  3. brandon says:

    You should never add a viewcontroller’s view to another viewcontroller. That may work now in iOS5 but it didn’t work in iOS4 and shouldn’t work 100% of the time.

  4. Bilal says:

    @brandon,
    Where do you add the initWithCoder method?

  5. Bilal says:

    Hello,
    Where do you add the initWithCoder code? :)

    Thanks in advance.

  6. iJar says:

    Good question.
    Where to put the initWithCoder code?

  7. rogerio says:

    In center or right controller.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>