在现有的Xcode故事板上使用pkrevealcontroller

我正在尝试将pkrevealcontroller滑动菜单集成到现有的具有segues的故事板的iOS项目中。我扩展了UINavigationViewController,并将新类链接到故事板上的Nav Controller。 在我的应用程序委托中,我执行以下操作:

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; 

当我运行应用程序时,它成功地将滑动菜单图标添加到导航栏,前视图按照我的需要滑动。 但是它并没有使用我在故事板上添加的标题或细节。 我正在尝试甚至可能。

我认为问题是你正在实例化一个新的frontViewController – 这不是你的故事板中的那个。 我不确定如何做到这一点,但我会尝试这样做。 我将在故事板中添加一个UIViewController – 将其类更改为PKRevealController,并使其成为故事板中的初始控制器,但不要将其连接到其余的场景。 在IB中给你的MainNavViewController一个标识符,然后将你的应用程序委托中的代码改为:

 - (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; } 

我的应用程序委托没有revealControllervariables,所以必须创build该手册,是你必须做的事情?

Swift中使用这个,

 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 }