SWRevealViewController没有StoryBoard和TIBgle与UIButton

时间:2017-03-11 15:23:12

标签: ios objective-c iphone swrevealviewcontroller

我正在尝试使用没有故事板和UIButton的SWRevealViewController。我的项目有两个带有nib的UIViewControllers。主要的一个叫做ViewController,另一个叫做MenuViewController。

在我的ViewController中,我有以下代码:

- (void)viewDidLoad {
    [super viewDidLoad];

    MenuViewController *menuView;

    SWRevealViewController *revealViewController = [[SWRevealViewController alloc] initWithRearViewController:menuView frontViewController:self];

    if ( revealViewController )
    {
        [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
    }
}

- (IBAction)toggleMenu:(id)sender {
    NSLog(@"Toggling menu");
    SWRevealViewController *revealController = self.revealViewController;
    [revealController rightRevealToggleAnimated:YES];
}

切换菜单按钮按预期打印“切换菜单”,但不显示菜单控制器。我知道这不是使用SWRevealViewController的传统方式,但有人有任何想法如何让它工作?

3 个答案:

答案 0 :(得分:0)

在viewDidLoad()

中添加以下行
self.revealViewController.delegate = self;

答案 1 :(得分:0)

你可以尝试一下这些修改。它对我有帮助。

- (IBAction)toggleMenu:(id)sender{
    [self.btn addTarget:self.revealViewController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];
}

答案 2 :(得分:0)

以下是我用来为SWRevealViewController设置两个(左和右)视图控制器的两种方法。只需在viewDidLoad中调用它们。

-(void) initSlideMenu
{
    SWRevealViewController * menuViewController =  (SWRevealViewController *)self.revealViewController;

    if (menuViewController)
    {
        [_menuButton setTarget:self.revealViewController];
        [_menuButton setAction:@selector(revealToggle:)];
        [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
    }
}
-(void) initRightMenu
{
    SWRevealViewController * rightViewController = (SWRevealViewController *)self.revealViewController;
    if (rightViewController)
    {
        rightViewController.rightViewRevealOverdraw =0.0f;
        [_notificationButton setTarget:self.revealViewController];
        [_notificationButton setAction:@selector(rightRevealToggle:)];
        [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
    }
}