Facing new challenges everyday

How to add a ViewDeck into a StoryBoard scene

April 3rd, 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!

DZoneGoogle BookmarksFacebookEvernoteLinkedInDeliciousShare

8 Comments »

  1. Darius says

    Could you serve little demo somewhere? :)

    April 23rd, 2012 | #

  2. Darius says

    Done it by my self:
    http://dl.dropbox.com/u/107952/inferisStoryboardExample.zip

    April 24th, 2012 | #

  3. 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;
    }

    June 5th, 2012 | #

  4. 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.

    June 5th, 2012 | #

  5. Bilal says

    @brandon,
    Where do you add the initWithCoder method?

    September 20th, 2012 | #

  6. Bilal says

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

    Thanks in advance.

    September 21st, 2012 | #

  7. iJar says

    Good question.
    Where to put the initWithCoder code?

    November 21st, 2012 | #

  8. rogerio says

    In center or right controller.

    November 21st, 2012 | #

Leave a comment

:mrgreen: :neutral: :twisted: :shock: :smile: :???: :cool: :evil: :grin: :oops: :razz: :roll: :wink: :cry: :eek: :lol: :mad: :sad:
*

RSS feed for these comments. | TrackBack URI

Visitors Around the World

Polls

How Is My Site?

View Results

Loading ... Loading ...

Categories

Meta

Links

Advertising

hosted by easy2use.net