Using pkrevealcontroller on an existing Xcode storyboard

I am trying to integrate the pkrevealcontroller sliding menu into an existing iOS project that has an existing storyboard with segues, etc. I extended the UINavigationViewController and linked my new class to the Nav Controller on the storyboard. In my application, I do the following:

MainNavViewController *frontViewController = [[MainNavViewController alloc] initWithRootViewController:[[myRootViewController alloc] init]]; UIViewController *rightViewController = [[menuViewController alloc] init]; self.revealController = [PKRevealController revealControllerWithFrontViewController:frontViewController rightViewController:rightViewController options:nil]; self.window.rootViewController = self.revealController; 

When I launch the application, it successfully adds a sliding menu icon to the navigation bar, and the front panel opens as I want. But it does not use the title or snippets that I added to the storyboard. I'm even trying to do it.

+3
ios iphone storyboard uinavigationcontroller
source share
3 answers

I think the problem is that you are creating a new frontViewController - this is not the one in your storyboard. I'm not quite sure how to do this, but I would try it like this. I would add a UIViewController to the storyboard - change my class to PKRevealController and make it the initial controller in the storyboard, but I do not connect it to the rest of the episodes. Give your MainNavViewController the identifier in IB, and then change the application code to this:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.revealController = (PKRevealController *)self.window.rootViewController; UIViewController *rightViewController = [[menuViewController alloc] init]; MainNavViewController *frontViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"frontViewController"]; [self.revealController setFrontViewController:frontViewController]; [self.revealController setRightViewController:rightViewController]; return YES; } 
+10
source share

My application delegate does not have the revealController variable, so I needed to create this guide, is that what you need to do?

0
source share

In Swift, use this,

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { var frontViewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("frontVC") as! UIViewController var leftViewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("leftVC") as! UIViewController var revealController:PKRevealController = PKRevealController(frontViewController: frontViewController, leftViewController: leftViewController) self.window?.rootViewController = revealController return true } 
0
source share

All Articles