我使用SWRevealViewController在我的应用程序中添加了侧边栏菜单。我在设置视图控制器的位置输入了SideBarViewController,让我们说OptionAViewController。我使用揭示视图控制器segue打开此新视图OptionAViewController。我想从OptionAViewController实现后退按钮以返回SideBarViewController

这是我设置optionAViewController的方法。这可行。

//SideBarViewController

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ( [segue isKindOfClass: [SWRevealViewControllerSegue class]] ) {
    SWRevealViewControllerSegue *swSegue = (SWRevealViewControllerSegue*) segue;

    swSegue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc) {

        UINavigationController* navController = (UINavigationController*)self.revealViewController.frontViewController;
        //[navController pushViewController:dvc animated: NO ];
        [navController setViewControllers: @[dvc] animated: NO ];
        [self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
    };
}

}

这就是我试图在OptionAViewController中实现后退按钮的方式。我尝试了popViewController,但是崩溃了。我也尝试了其他选项,但是没有一个起作用。您知道选择器应该是什么吗?
 //back button in ViewDidLoad (OptionAViewController)
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:@"backButton.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(popViewControllerAnimated:)forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.leftBarButtonItem = barButtonItem;

最佳答案

检查此reference link以更好地了解SWRevealViewController。

这将带回您的侧边菜单。

[_menuButton addTarget:self.revealViewController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];

不要忘记
#import "SWRevealViewController.h"

在您的视图控制器中。

10-06 02:56