2

I have some problems with ViewDeck with my app.
I'm trying to use it with storyboard and the examples only shows how to use it with nibfiles. I have checked out many ways to do it here on stackexchange but i don't seem to get it to work.

My code in appdelegate.m file:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    //UIViewController* leftController = [[UIViewController alloc] init];

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

    RightViewController* rightController = [[RightViewController alloc] initWithNibName:@"RightViewController" bundle:nil];

    ViewController* centerController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.centerController = [[UINavigationController alloc] initWithRootViewController:centerController];
    IIViewDeckController* deckController = [[IIViewDeckController alloc] initWithCenterViewController:self.centerController rightViewController:rightController];

    deckController.rightSize = 100;

    self.window.rootViewController = deckController;
    [self.window makeKeyAndVisible];
    return YES;

}

I of course i get the expected error:

2012-12-29 03:55:18.501 Network[27451:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/Rostgaard/Library/Application Support/iPhone Simulator/6.0/Applications/C2BADD3B-660E-4363-8FC7-932B4E9D6172/Network.app> (loaded)' with name 'RightViewController''
*** First throw call stack:
(0x17cd012 0x15f2e7e 0x17ccdeb 0x755fac 0x61ae37 0x61b418 0x61b648 0x61b882 0xbcdf 0xe673 0xb7e2 0xada7 0x61d753 0x61da7b 0x61e964 0x581877 0x5885a3 0x580eed 0x56ab56 0x56adbf 0x56af55 0x573f67 0x2546 0x5377b7 0x537da7 0x538fab 0x54a315 0x54b24b 0x53ccf8 0x261adf9 0x261aad0 0x1742bf5 0x1742962 0x1773bb6 0x1772f44 0x1772e1b 0x5387da 0x53a65c 0x226d 0x2195 0x1)
libc++abi.dylib: terminate called throwing an exception
(lldb) 
rostgaard
  • 325
  • 1
  • 6
  • 19

3 Answers3

9

Here is the code I'm using which works fine:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
    UIViewController* menuController = [mainStoryboard instantiateViewControllerWithIdentifier:@"LeftSideMenu"];

    UINavigationController* navigationController = (UINavigationController *) self.window.rootViewController;
    self.viewDeckController =  [[IIViewDeckController alloc] initWithCenterViewController:navigationController leftViewController:menuController rightViewController:nil];
    self.window.rootViewController = self.viewDeckController;
}
masha
  • 316
  • 3
  • 9
  • As a follow up to this - when you are setting up the `menuController`, how would you programtically change the `CenterViewController` based on what you select in the menu? I though it was simply `setCenterViewController: NEW_CONTROLLER_NAME`, but this has the effect of resetting the viewController altogether. Thanks! – daspianist Nov 14 '13 at 03:54
  • I keep a hold of all the view controllers in a dictionary, so my code ends up looking like this:`[self.viewDeckController setCenterController:[self.masterViewController getViewControllerForKey:cell.titleLabel.text]];` – masha Nov 27 '13 at 14:44
5

Well, solved this myself by using ECSlidingViewController instead, already optimized with storyboard.

https://github.com/edgecase/ECSlidingViewController

Just in case anyone runs into the same problem.

rostgaard
  • 325
  • 1
  • 6
  • 19
  • Tried this myself, but after implementing this, it had some drawbacks. First when you drag it it somehow twitches and lags. So i switched to IIViewDeckController. But ECSlidingViewController example project helped me implementing storyboards. – Lukas May 28 '13 at 12:47
1

Try this tutorial project, it works

Rahul Patel
  • 5,858
  • 6
  • 46
  • 72
Egor
  • 423
  • 1
  • 4
  • 13