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



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

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

要在视图上获取后退按钮,我需要使用"显示详细信息 Segue",但我还需要"某处"导航控制器才能显示后退按钮。(我并不是说我需要在 segue 之后使用导航控制器 - 我已经有了 - 但我之前在某个地方需要它)。

是否有人以这种方式使用SWRevealViewController或知道如何实现这一点?我应该"在哪里"放置导航控制器?

谢谢!

我想出的唯一可行的解决方案是在UIView上使用一个类别,它可以做我的细节Segues。

@interface UIViewController (SidebarView)

  • (void)setupSidebarWithGestureRecognizer:(BOOL)useGestureRecognizer;
  • (无效)打开设置页面;
  • (无效)打开关于页面;

@end

以及 openAboutPage 的 .m -file 代码:

/* 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";
}

和设置侧边栏与手势识别器...方法

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

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

最新更新