4

I'm using SWRevealViewController for implementing two side navigation views in my application. I followed the story board method and successfully implemented the rear view and front view. I tried setting right view exactly like the rear view via storyboard, but couldn't do it.

I have set the reveal view controller segue to "sw_right" but it looks like it is not being recognized by - (void)prepareForSegue:(SWRevealViewControllerSegue *)segue sender:(id)sender which is called twice for "sw_rear" and "sw_front"

What Am I missing? enter image description here

- (void)prepareForSegue:(SWRevealViewControllerSegue *)segue sender:(id)sender
{
// $ using a custom segue we can get access to the storyboard-loaded rear/front view controllers
// the trick is to define segues of type SWRevealViewControllerSegue on the storyboard
// connecting the SWRevealViewController to the desired front/rear controllers,
// and setting the identifiers to "sw_rear" and "sw_front"

// $ these segues are invoked manually in the loadView method if a storyboard
// was used to instantiate the SWRevealViewController

// $ none of this would be necessary if Apple exposed "relationship" segues for container view controllers.

NSString *identifier = segue.identifier;
if ( [segue isKindOfClass:[SWRevealViewControllerSegue class]] && sender == nil )
{
    if ( [identifier isEqualToString:SWSegueRearIdentifier] )
    {
        segue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc)
        {
            [self _setRearViewController:dvc animated:NO];
        };
    }
    else if ( [identifier isEqualToString:SWSegueFrontIdentifier] )
    {
        segue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc)
        {
            [self _setFrontViewController:dvc animated:NO];

        };
    }
    //This is never executed even after setting the identifier
    else if ( [identifier isEqualToString:SWSegueRightIdentifier] ) 
    {
        segue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc)
        {
            [self _setRightViewController:dvc animated:NO];
        };
    }
  }
}
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
LoveMeSomeFood
  • 3,137
  • 7
  • 30
  • 53
  • what the problem actually u meet at nw – Anbu.Karthik Jul 03 '14 at 05:01
  • I think u r not swipe the Right View controller, correct – Anbu.Karthik Jul 03 '14 at 05:36
  • @Anbu.Karthik I'm only using the bar button to reveal and hide the rear and right view. When I set the reveal view controller segue id as `sw_right` in the story board the rightViewController is not set. Apart from adding a custom segue is there anything else I should in story board? – LoveMeSomeFood Jul 03 '14 at 15:05
  • any ideas ab this question http://stackoverflow.com/questions/31481559/swrevealviewcontroller-make-sidebar-button-static-make-the-rearview-appear-on-to – Nischal Hada Jul 18 '15 at 04:22

5 Answers5

9

enter image description here

here is the sample project , this is working fine I worked out for your self, the download link is

https://www.sendspace.com/file/0l2ndd

after downloaded the project u want to delete the project , use this link

https://www.sendspace.com/delete/0l2ndd/1b1bd537ad852b2fdea9b9a0cce3390f

here u were need the right swipe on the front view controller , add the UIBarButtonItem in the particular view Controller

    @property (strong, nonatomic) IBOutlet UIBarButtonItem *rightIcon;   //this is for left bar button Item
    @property (nonatomic) IBOutlet UIBarButtonItem* revealButtonItem;  //this is for right bar button Item

and add the some functions is View DidLoad

- (void)viewDidLoad
{
[super viewDidLoad];

 //action for left Swipe
[self.revealButtonItem setTarget: self.revealViewController];
[self.revealButtonItem setAction: @selector( revealToggle: )];
[self.navigationController.navigationBar addGestureRecognizer:  self.revealViewController.panGestureRecognizer];

//action for Right Swipe
[self.rightIcon setTarget: self.revealViewController];
[self.rightIcon setAction: @selector( rightRevealToggle: )];
[self.navigationController.navigationBar addGestureRecognizer: self.revealViewController.panGestureRecognizer];
}

Swift

override func viewDidLoad() {
super.viewDidLoad()
//action for left Swipe
self.revealButtonItem.target = self.revealViewController
self.revealButtonItem.action = "revealToggle:"
    self.navigationController.navigationBar.addGestureRecognizer(self.revealViewController.panGestureRecognizer)
//action for Right Swipe
self.rightIcon.target = self.revealViewController
self.rightIcon.action = "rightRevealToggle:"
    self.navigationController.navigationBar.addGestureRecognizer(self.revealViewController.panGestureRecognizer)
}
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
  • any ideas ab this question http://stackoverflow.com/questions/31481559/swrevealviewcontroller-make-sidebar-button-static-make-the-rearview-appear-on-to – Nischal Hada Jul 18 '15 at 04:22
  • @Anbu- I just find that the link you provided is not working to download the project let me know how to implement side bar when SWreveal View controller is not your initial view. Since when I push it it shows it's own navigation bar on above of view itself. – iEinstein Feb 29 '16 at 11:25
5

I figured out what the problem was. In loadStoryboardControllers method [self performSegueWithIdentifier:SWSegueRightIdentifier sender:nil]; was commented out. If we implement right view controller this has to be uncommented.

LoveMeSomeFood
  • 3,137
  • 7
  • 30
  • 53
  • any ideas ab this question http://stackoverflow.com/questions/31481559/swrevealviewcontroller-make-sidebar-button-static-make-the-rearview-appear-on-to – Nischal Hada Jul 18 '15 at 04:23
1

You requested that I look at this thread.

I do not have experience with storyboards.

So, I am pasting below the code I have in my projects that allow for the Right Hand Side. Take a look at the section I commented. Hopefully, this will set you on the right path.

Good luck

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions
{
    UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window = window;

    FrontViewController *frontViewController = [[FrontViewController alloc] init];
    RearViewController *rearViewController = [[RearViewController alloc] init];

    UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
    UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];

    SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController     frontViewController:frontNavigationController];
    revealController.delegate = self;

// THIS SECTION RIGHT BELOW IS PROBABLY WHAT YOU WANT TO LOOK AT
    RightViewController *rightViewController = rightViewController =     [[RightViewController alloc] init];
    rightViewController.view.backgroundColor = [UIColor greenColor];

    revealController.rightViewController = rightViewController;

    revealController.bounceBackOnOverdraw=NO;
    revealController.stableDragOnOverdraw=YES;

    self.viewController = revealController;

    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}
Timothy Jeffcoat
  • 775
  • 2
  • 9
  • 26
1

There is a try-catch condition between line on 435 to 444 on SWRevealViewController.m. Just rearrange the statement as following

        [self performSegueWithIdentifier:SWSegueRightIdentifier sender:nil];
        [self performSegueWithIdentifier:SWSegueFrontIdentifier sender:nil];
        [self performSegueWithIdentifier:SWSegueRearIdentifier sender:nil];

Now my right-menu/rightViewController is working even though i am not using the leftmenu/rearViewController.

Shad
  • 1,587
  • 2
  • 20
  • 29
1

you can also do what shad suggested. But if you are getting a flag with the right you can just replace

- (void)loadStoryboardControllers


if ( self.storyboard && _rearViewController == nil )
{
    //Try each segue separately so it doesn't break prematurely if either Rear or Right views are not used.
    @try
    {
        [self performSegueWithIdentifier:SWSegueRearIdentifier sender:nil];
    }
    @catch(NSException *exception) {}

    @try
    {
        [self performSegueWithIdentifier:SWSegueFrontIdentifier sender:nil];
    }
    @catch(NSException *exception) {}

    @try
    {
        [self performSegueWithIdentifier:SWSegueRightIdentifier sender:nil];
    }
    @catch(NSException *exception) {}
}


}

with

 - (void)loadStoryboardControllers
{

//[self performSegueWithIdentifier:SWSegueRightIdentifier sender:nil];
[self performSegueWithIdentifier:SWSegueFrontIdentifier sender:nil];
[self performSegueWithIdentifier:SWSegueRearIdentifier sender:nil];

}

as you can see i commented out

//[self performSegueWithIdentifier:SWSegueRightIdentifier sender:nil];

becasue thats the one giving you an issue. If its the front or rear you can do the same

Miguel
  • 333
  • 2
  • 13
  • any ideas ab this question http://stackoverflow.com/questions/31481559/swrevealviewcontroller-make-sidebar-button-static-make-the-rearview-appear-on-to – Nischal Hada Jul 18 '15 at 04:24