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

dix*_*_va 3 iphone storyboard uinavigationcontroller ios

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

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;
Run Code Online (Sandbox Code Playgroud)

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

rde*_*mar 10

我认为问题是你正在实例化一个新的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;
}
Run Code Online (Sandbox Code Playgroud)