iOS SWReveal侧边栏,带有Detail Segue的链接

时间:2015-04-30 07:19:57

标签: ios uinavigationcontroller uistoryboardsegue swrevealviewcontroller

我的iOS应用程序基于John-Lluch的SWRevealViewController来获取侧边栏导航。我遇到了导航问题,我不知道如何解决。

我希望其中一个菜单项指向不包含侧边栏而是包含后退按钮的页面。 (其他菜单项指向可以打开侧栏的页面)。

要在视图上获得后退按钮,我需要使用“显示详细信息”,但我还需要一个导航控制器"某处"用于显示后退按钮。 (我不是说我需要一个导航控制器在segue之后 - 我已经有了 - 但我之前需要它。)

有人以这种方式使用SWRevealViewController或知道如何实现这一目标吗? "其中"我应该放置导航控制器吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

我提出的唯一可行解决方案是使用UIView上的类别,可以执行我的细节分段。

@interface UIViewController(SidebarView)

  • (无效)setupSidebarWithGestureRecognizer:(BOOL)useGestureRecognizer;
  • (无效)openSettingsPage;
  • (无效)openAboutPage;

@end

.m - openAboutPage的文件代码:

/* This method is called by the sidebar. If the sidebar opens the settings page from itself, the back button
 * doesn't know where it should point. This method opens the about menu when the sidebar tells it to, and the back button
 * is pointing to the home page. */
- (void)openAboutPage {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *about = [storyboard instantiateViewControllerWithIdentifier:@"About"];
    [self.revealViewController rightRevealToggleAnimated:YES];
    [self.navigationController pushViewController:about animated:NO];
    self.navigationController.navigationItem.title = @"About";
}

和setupSideBarWithGestureRecognizer ...方法

- (void)setupSidebarWithGestureRecognizer:(BOOL)useGestureRecognizer {
    SWRevealViewController *revealViewController = self.revealViewController;
    if (revealViewController) {
        UIBarButtonItem *sidebarButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"reveal"] landscapeImagePhone:[UIImage imageNamed:@"reveal"] style:UIBarButtonItemStylePlain target:self.revealViewController action:@selector(rightRevealToggle:)];
        self.navigationItem.rightBarButtonItem = sidebarButton;
        if(useGestureRecognizer) {
            [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
        }
    }
}

然后,对于我想要显示侧边栏的每个页面,我只需在该视图控制器的[self setupSidebar:YES];方法中调用viewWillAppear