ipup / PPRevealSideViewController

A new container controller to easily push views on side like Path or Facebook
www.ipup.pro
Other
821 stars 194 forks source link

How to initialize PPRevealSideViewController in a storyboard? #21

Closed bagusflyer closed 12 years ago

bagusflyer commented 12 years ago

This component looks great. But there is only one issue for me to add it to my ios 5 project. My question is:

How to initialize PPRevealSideViewController in a storyboard? (Which will be root viewcontroller)

Any suggestion? Thanks

ipodishima commented 12 years ago

I'm not a huge fan of storyboards, so don't have good skills with it, but as far as I know you can't. The only way I see is to init the controller with storyboard, then popAndPush a new center controller by code. This will place a rootviewcontroller.

xaxa06 commented 12 years ago

Hello, here is how we overcame this storyboard limitation in our project (storyboard sucks by the way, really.):

Let's say you have the following view hierarchy in your storyboard before PPReveal integration: TabBar > NavController > HelloWorldViewController and you want to integrate the PPReveal in the HelloWorldViewController.

  1. Create a subclass of PPRevealController in your project (let's call it PPRevealContainer)
  2. Create a regular view controller in your storyboard (let's call it PPRevealSBContainer), that you insert instead of the HelloWorldViewController.

It now looks like this: TabBar > NavController > PPRevealContainer,

and then you have your HelloWorldViewController lying somewhere not connected to anything (since you can't connect a regular view controller to another and you can't create custom view controllers "containers" in storyboard - once again, suck big time)

  1. Still in storyboard, set the Custom Class of your PPRevealSBContainer (in identity inspector) to your subclass "PPRevealContainer")
  2. Back to your subclass "PPRevealContainer", remove all the unwanted crap added by XCode and define the following method (which will by called when storyboard will load PPRevealSBContainer):
- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];

    if(self){
        // Custom initialization
        // init your HelloWorldViewController by its Storyboard ID (to be set in the identity inspector of HelloWorldViewController)
        HelloWorldViewController* helloVC = [[UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:NULL] instantiateViewControllerWithIdentifier:@"helloworld"]; 

        // Prepare the root view controller of the PPReveal, here a Navigation Controller as recommended in PPReveal examples
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:helloVC];

        // Call the legacy PPReveal initialiser method, so it can deal with all its stuffs
        self = [self initWithRootViewController:nav];

        // Only if you want the PPRevealContainer to be the delegate of PPReveal events, otherwise you can also set it on your HelloWorldViewController if you prefer.
        self.delegate = self;
    }
    return self;
}

and it should work.

Here is the final picture of your view hierarchy - the part between () won't be interconnected in storyboard, since you couldn't connect the PPRevealSBContainer to anything: TabBar > NavController > PPRevealSBContainer (> NavController > HelloWorldViewController)

in otherwords, storyboard handles all the hierarchy until the PPRevealSBContainer, then its your subclass PPRevealContainer which does the rest of the work to display your HelloWorldViewController

Hope this helped! Good luck

ipodishima commented 12 years ago

Thanks xaxa06, hope it will be helpful for the guys who works with storyboard. And you're right, storyboard does suck ;)

wayn commented 11 years ago

Thanks xaxa06, this works fine, but has another bug for this, I found hidesBottomBarWhenPushed will not work.

victorynaveen commented 8 years ago

Hi ,xaxa06 !!!,

Can you please send me the sample code which you integrated pprevealsideview controller with storyboard. Please its very urgent for me..