iOS 带有 Detail Segue 链接的 SWReveal 侧边栏
iOS SWReveal sidebar with links to Detail Segue
我的 iOS 应用程序基于 John-Lluch 的 SWRevealViewController
来获得侧边栏导航。我 运行 遇到了一个我不知道如何解决的导航问题。
我希望其中一个菜单项指向一个不包含边栏但包含后退按钮的页面。 (其他菜单项指向可以打开侧边栏的页面)。
要在视图上获得后退按钮,我需要使用 Show Detail Segue,但我还需要一个导航控制器 "somewhere" 才能显示后退按钮。 (我并不是说在转场之后我需要一个导航控制器——我已经有了——但我之前在某个地方需要它)。
有人以这种方式使用过 SWRevealViewController 或知道如何实现吗? "Where" 我应该放置一个导航控制器吗?
谢谢!
我想出的唯一可行的解决方案是在 UIView 上使用一个类别,它可以完成我的 Detail Segues。
@interface UIViewController (SidebarView)
- (void)setupSidebarWithGestureRecognizer:(BOOL)useGestureRecognizer;
- (void)打开设置页面;
- (void)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];
}
}
}
然后对于我想显示侧边栏的每个页面,我只需在该视图控制器的 viewWillAppear
方法中调用 [self setupSidebar:YES];
。
我的 iOS 应用程序基于 John-Lluch 的 SWRevealViewController
来获得侧边栏导航。我 运行 遇到了一个我不知道如何解决的导航问题。
我希望其中一个菜单项指向一个不包含边栏但包含后退按钮的页面。 (其他菜单项指向可以打开侧边栏的页面)。
要在视图上获得后退按钮,我需要使用 Show Detail Segue,但我还需要一个导航控制器 "somewhere" 才能显示后退按钮。 (我并不是说在转场之后我需要一个导航控制器——我已经有了——但我之前在某个地方需要它)。
有人以这种方式使用过 SWRevealViewController 或知道如何实现吗? "Where" 我应该放置一个导航控制器吗?
谢谢!
我想出的唯一可行的解决方案是在 UIView 上使用一个类别,它可以完成我的 Detail Segues。
@interface UIViewController (SidebarView)
- (void)setupSidebarWithGestureRecognizer:(BOOL)useGestureRecognizer;
- (void)打开设置页面;
- (void)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];
}
}
}
然后对于我想显示侧边栏的每个页面,我只需在该视图控制器的 viewWillAppear
方法中调用 [self setupSidebar:YES];
。