8

I'm trying to integrate PKRevealController into an existing project of mine.

https://github.com/pkluz/PKRevealController

How do I set up my left view controller, right view controller, and front view controller if I'm using storyboard? The readme says to do...

PKRevealController *revealController = [PKRevealController revealControllerWithFrontViewController:frontVC leftViewController:leftVC options:options];

self.window.rootViewController = revealController;

Where would I put these lines of code in my existing storyboard project? Or are there any alternatives to set this up?

Thanks!

Rohan Agarwal
  • 2,167
  • 1
  • 24
  • 34
  • 3
    I answered a similar question here: [Using pkRevealController on existing Xcode storyboard](http://stackoverflow.com/questions/14824959/using-pkrevealcontroller-on-existing-xcode-storyboard/14825615#14825615) – rdelmar Feb 14 '13 at 23:42

2 Answers2

2

Just set the segue destination controller's type to PKRevealController and set storyboard ID for front, left and right view controller.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

  if ([segue.identifier isEqualToString:@"ToMain"]) {

    PKRevealController* prc = segue.destinationViewController;

    prc.frontViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"FrontViewController"];
    prc.leftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LeftViewController"];
    prc.rightViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"RightViewController"];

  }
}
Hans One
  • 3,329
  • 27
  • 28
  • I don't get it. Does it mean I should make `PKRevealController` entry-point of my storyboard ? Can't I just invoke PKRevealController from tab bar button click handler ? – expert Sep 10 '13 at 07:12
  • 1
    It's worth noting that this doesn't work. You can set the view controller in IB to have a class of `PKRevealController` but when the segue happens, the screen is blank, just a translucent gray. – barndog Jul 26 '14 at 03:08
  • @startupthekid You need at least 5 view controller in the storyboard for my example to work: source view controller (where you put my example code), PKRevealController, front , left and right view controller. For front, left and right you have to set the storyboard IDs – Hans One Jul 29 '14 at 06:55
  • I have over 20. Still doesn't work. It's a bug in the last version. – barndog Jul 29 '14 at 17:04
  • OK. I dont use PKRevealController anymore. Instead I use ECSlidingViewController. Maybe it works better for you, too. – Hans One Jul 30 '14 at 08:07
2

I know this is an old thread, but I'm gonna out it here anyways :)

To make PKRevealController work with storyboard basically you'll need three view controllers.

  1. BaseController (i called it that), which get extended by the PKRevealController how's going to act as the base for the Main content controller and Navigation controller.

  2. MainController, which get set as the fronViewController.

  3. NaviController, which we basically use as the leftViewController, aka navigation menu.

FYI: You can design and code the MainController and NaviController from the stroyboard.

So this is how we do it; First we need to extend our BaseController with PKRevealController like this;

@interface MainController : PKRevealController

Second, still in BaseController, add these line to the viewDidLoad method;

//init the fonrViewController
UIViewController *homeController = [self.storyboard instantiateViewControllerWithIdentifier:@"homeScreen"];
//init the leftViewController
UIViewController *naviContrlller = [self.storyboard instantiateViewControllerWithIdentifier:@"quickNaviScreen"];

[self setFrontViewController:homeController];
[self setLeftViewController:naviContrlller];

Then set the PKRevealController delegate as;

self.delegate = self;

And that's it.

Laky
  • 632
  • 3
  • 10