iDevelopper / PBRevealViewController

A UIViewController subclass for revealing a left and/or right view controller above or below a main view controller.
MIT License
80 stars 16 forks source link

Remove slidemenu after pushing view controller #22

Closed riyanpratamap closed 7 years ago

riyanpratamap commented 7 years ago

Hi,

Is there any way to remove slidemenu after it pushed into some view controller? So, here is my hierarchy

NavController > ViewController A > ViewController B

I have table on ViewController A (which is view controller that hold slide menu). On every cell I pressed, I push into View Controller B with [self performSegueWithIdentifier:idmenu[indexPath.row] sender:self];

Its slidemenu still appear if we swipe from left, and I want to disable it. Is there any way to do it? Thank you!

iDevelopper commented 7 years ago

Do you mean avoid to open it when you are in ViewController B?

riyanpratamap commented 7 years ago

I am so sorry, it was sent before I finish asking my question. Now it's updated.

iDevelopper commented 7 years ago

Use the delegate method:

- (BOOL)revealControllerPanGestureShouldBegin:(PBRevealViewController *)revealController direction:(PBRevealControllerPanDirection)direction
{
    if (direction == PBRevealControllerPanDirectionRight) {
        // if (other test) {
        return NO;
        // }
    }
    return YES;
}
riyanpratamap commented 7 years ago

I think I do not conform to PBRevealViewController delegate on ViewController B. I just want to avoid slidemenu to open in ViewController B, because it simply pure view controller.

Am I missed something here?

iDevelopper commented 7 years ago

Do it in your main view controller (A). Adopt PBRevealViewController protocol, set the delegate to self and:

- (BOOL)revealControllerPanGestureShouldBegin:(PBRevealViewController *)revealController direction:(PBRevealControllerPanDirection)direction
{
    if (direction == PBRevealControllerPanDirectionRight) {
        UINavigationController *nc = (UINavigationController *)revealController.mainViewController;
        if ([nc.topViewController isKindOfClass:[ViewControllerB class]]) {
            return NO;
        }
    }
    return YES;
}

You can also subclass PBRevealViewController. Generally I create a RevealViewController subclassing PBRevealViewController to handle the delegate methods I need to.

riyanpratamap commented 7 years ago

It works! Thank you!