在现有的Xcode故事板上使用pkrevealcontroller [英] Using pkrevealcontroller on existing Xcode storyboard

查看:135
本文介绍了在现有的Xcode故事板上使用pkrevealcontroller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to integrate the pkrevealcontroller sliding menu into an existing iOS project that has an existing storyboard with segues, etc. I extended UINavigationViewController and linked my new class to the Nav Controller on the storyboard. In my app delegate 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;

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

When I run the application, it successfully adds the sliding menu icon to the navigation bar, and the frontview slides as I want it. But it is not using the title or segues I have added on the storyboard. Is what I'm trying even possible.

推荐答案

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

I think the problem is that you're instantiating a new frontViewController -- that's not the one that's in your storyboard. I'm not exactly sure how to do this, but I would try it like this. I would add a UIViewController in the storyboard -- change its class to PKRevealController, and make it the initial controller in the storyboard, but don't hook it up to the rest of the scenes. Give your MainNavViewController an identifier in IB, then change the code in your app delegate 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;
}

这篇关于在现有的Xcode故事板上使用pkrevealcontroller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆