iOS Integrate PKRevealController with Storyboard & Auto Layout

时间秒杀一切 提交于 2019-12-21 09:27:17

问题


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!


回答1:


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"];

  }
}



回答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.



来源:https://stackoverflow.com/questions/14885887/ios-integrate-pkrevealcontroller-with-storyboard-auto-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!