如何将SWRevealViewController与轻松的搜索结合使用? [英] How do I use SWRevealViewController with unwind segues?

查看:78
本文介绍了如何将SWRevealViewController与轻松的搜索结合使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列视图,这些视图在导航控制器上彼此叠加.我想对这些视图做两件事:

I have a sequence of views that are pushed on top of each other on a Navigation Controller. I would like to do two things with these views:

  1. 要从所有菜单中打开后菜单视图;
  2. 能够导航 使用Unwind segues返回堆栈.
  1. To open the Rear menu view from all of them;
  2. To be able to navigate back the stack using Unwind segues.

我发现,如果我使用常规的推键顺序将视图控制器彼此推压,则展开顺序将按预期方式工作,但是每个视图控制器上的self.revealViewController均未设置,因此无法调用Menu使用manifestToggle:选择器.

I found out that if I push view controllers on top of each other using regular push segues then the unwind segue works as expected, but then the self.revealViewController on each view controller is not set and the Menu can't be called using the revealToggle: selector.

如果将推送选择更改为SWRevealViewControllerSeguePushController的子类,则视图将彼此叠加,并且可以使用revealToggle从任何一个菜单中调用Menu.不幸的是,展开的讨论停止了工作(我认为这可能是因为视图控制器是使用addChild而不是SWRevealViewController类上的pushViewController堆叠的.)

If I change the push segues to subclasses of SWRevealViewControllerSeguePushController then the views are pushed on top of each other and the Menu can be called from any of them using the revealToggle. Unfortunately, the unwind segues stop working (I think this might be because the view controllers are stacked using addChild instead of pushViewController on the SWRevealViewController class).

是否可以与SWRevealViewController和Unwind Segues一起使用?

Is there a way of working together with SWRevealViewController and Unwind Segues?

下面有一个示例情节提要:

Below there is an example storyboard:

第一个视图控制器是导航控制器;第二个是SWRevealViewController;下面的三个视图控制器彼此导航,第三个视图控制器与第一个视图控制器隔离.第一个和第三个控制器具有打开菜单的按钮.

The first view controller is the navigation controller; the second is the SWRevealViewController; the three view controllers below navigate one to each other, and the third has an unwind segue to the first. The first and third controllers have buttons that open the menu.

正如我之前所说,如果底视图控制器之间的顺序是常规的推送顺序,则展开顺序将按预期工作;第一个视图控制器的菜单按钮可以正常工作(因为它直接连接到SWRevealViewController),但是第三个视图控制器的菜单按钮却不起作用.

As I stated before, if the segues between the bottom view controllers are regular push segues then the unwind segue works as expected; the menu button from the first view controller works (as it is connected directly to the SWRevealViewController), but the menu button from the third view controller doesn't.

将segue类型切换为SWRevealViewControllerSeguePushController可使第一个和第三个视图控制器的菜单按钮正常工作,但是展开的segue停止工作.

Switching the segue types to SWRevealViewControllerSeguePushController makes the menu buttons from the first and third view controllers work correctly, but the unwind segue stops working.

哦,我使用"popToRootViewControllerAnimated:"进行了测试,如果将segue设置为SWRevealViewControllerSeguePushController,它也将不起作用.

Oh, and I tested using "popToRootViewControllerAnimated:" and it also doesn't work if the segues are set to SWRevealViewControllerSeguePushController.

推荐答案

我在 SWRevealViewControllers github网站,并从Patrick Bodet那里得到了答复,他对此非常有帮助.我将在下面发布答案,这样可能会对与我一样的人有所帮助.

I posted this question on SWRevealViewControllers github site and received an answer from Patrick Bodet who was EXTREMELY helpful. I will post the answer below so it may help somebody in the same situation as I.

我不得不更新情节提要,并添加了一个额外的导航控制器,如下所示.

I had to update the storyboard and added an additional navigation controller as shown below.

如图所示,我希望能够将视图控制器彼此推到一起,并且还可以将segues放到登录"屏幕(从菜单)和堆叠的视图控制器中.

As shown in the figure, I wanted to be able to push view controllers on top of each other and also to unwind the segues both to the Login screen (from the Menu) and from stacked view controllers.

在我以前的尝试中,SWRevealViewController似乎无法应付适当的导航任务. Patrick的第一个建议是将原始导航控制器从RevealViewController之前移到First视图控制器之前.确实有效,因为我仍然需要能够将菜单中的搜索功能解开到登录"屏幕,因此我需要一个附加的导航控制器.

On my previous attempts, it seemed as if SWRevealViewController wasn't able to cope with proper navigation segues. Patrick's first suggestion was to move the original navigation controller from before the RevealViewController to before the First view controller. That actually worked, by I still needed to be able to unwind segue from the Menu to the Login screen, so I needed an additional navigation controller.

根据Patrick的建议,我添加了一个附加的导航控制器.令人尴尬的是,最后我意识到从第三个指向第一个视图控制器的按钮既有作用,又有指向第一个的功能,所以这就是为什么它表现得很奇怪的原因! :-(

As suggested by Patrick, I added an additional Navigation Controller. And embarrassingly at the end I realised the button that pointed from the third to the first view controller had both an ibaction and a segue to the first, so that was why it was acting all weird! :-(

因此,对于上面显示的情节提要,为了正常工作,您只需要对视图控制器使用常规的Push segues.无需使用SWRevealViewControllerSeguePushController segues.

So, for the storyboard shown above, in order to work you just use regular Push segues for the view controllers. No need to use SWRevealViewControllerSeguePushController segues.

第一和第三视图控制器的代码如下:

The code for First and Third view controllers is like this:

#import "ThirdViewController.h"
#import "SWRevealViewController.h"
#import "FirstViewController.h"

@interface ThirdViewController ()
@property (weak, nonatomic) IBOutlet UIBarButtonItem *menuButton;
@end

@implementation ThirdViewController 
- (void)viewDidLoad {
    [super viewDidLoad];

    SWRevealViewController *revealViewController = self.revealViewController;

    if (revealViewController) {
        [self.menuButton setTarget: revealViewController];
        [self.menuButton setAction: @selector( revealToggle: )];
    }
}

- (IBAction)returnToFirst:(id)sender {
    [self performSegueWithIdentifier:@"First" sender:self];
    //[self.navigationController popToRootViewControllerAnimated:YES];
}  
@end

这篇关于如何将SWRevealViewController与轻松的搜索结合使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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