3

I am using ECSlidingViewController for my menu, I have an initial controller, menu and a home page and a login page. In the initial view controller if the user is authenticated they see the home page else I show the login dialog. (using the self topViewController)

Everything seems to be working fine, the problem I have is that when I am in the home view controller

if I click on the menu icon (which I added programmatically) the menu shows up, but if I click again to close it, nothing happens, the menu remains visible.

I added a NSLog and I am able to see that I am calling the right method

- (IBAction)revealSidebar
{
 NSLog(@"reveal ");
    [self.slidingViewController anchorTopViewTo:ECRight];

}

However the menu doesn't hide itself.

Attached some screenshots to get the idea.

NSLog(@"here ");

Community
  • 1
  • 1
user714142
  • 57
  • 5
  • My menu item (icon) is linked to the revealSidebar action as shown above. How can I add 2 actions to the same button, one to display the menu and one to hide it? ithe tutorial only uses revealSidebar and it works fine, the only difference is that the icon in my case was not dragged and dropped but created programmatically. Thanks for your help! – user714142 Jun 21 '13 at 00:23
  • See my answer below. Call setAction: on your bar button item when you receive the notifications I mention. – geraldWilliam Jun 21 '13 at 00:27
  • Ah! I got it! let me try it. – user714142 Jun 21 '13 at 00:36
  • Something I just found out before trying your proposed answer. In my home controller I have a link to an external site, I use a UIWebView to display that website. In this viewcontroller there is a back button which dismisses the current UIWebView and takes the user to the home controller. What I noticed is that after the webview gets dismissed, the menu works perfectly. This happens only if I dismiss the view controller, if I don't click on any link, the menu slides from the left when I click on the menu icon but I am unable to close it. – user714142 Jun 21 '13 at 01:02
  • Strange. I don't know why that happens but you will, I think, want to swap out your bar button item's action either way. – geraldWilliam Jun 21 '13 at 01:14
  • Hi GeraldWilliam, I registered to received both notifications: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleMenuDidShowNotification) name:SlidingViewUnderLeftWillAppear object:nil]; - (void)handleMenuDidShowNotification:(NSNotification *)notification { [menuicon addTarget:self action:@selector(closeMenu) forControlEvents:UIControlEventTouchUpInside]; } - (void)closeMenu:(id)sender { [self.slidingViewController anchorTopViewTo:ECRight]; } But nothing happens when I click on the UIButton, the tutorial doesn't implement this and works fine :( – user714142 Jul 02 '13 at 00:34

2 Answers2

1

ECSlidingViewController posts the following notifications (among others):

/** Notification that gets posted when the underLeft view will appear */
extern NSString *const ECSlidingViewUnderLeftWillAppear;

/** Notification that gets posted when the underLeft view will disappear */
extern NSString *const ECSlidingViewUnderLeftWillDisappear;

You can register to receive these notifications and then implement handler methods like this:

- (void)handleMenuDidShowNotification:(NSNotification *)notification
{
    [self.menuItem setAction:@selector(closeMenu:)];
}

- (void)handleMenuDidHideNotification:(NSNotification *)notification
{
    [self.menuItem setAction:@selector(openMenu:)];
}

- (void)closeMenu:(id)sender
{
    [self.slidingViewController anchorTopViewTo:ECRight];
}
- (void)openMenu:(id)sender
{
    [self.slidingViewController resetTopView];
}
geraldWilliam
  • 4,123
  • 1
  • 23
  • 35
0

Try upgrading to an appropriate version of ECSlidingViewController. The version used at the time this question was asked had issues with setting up the gestures too late. This issue was fixed in version 1.0.1.

Michael Enriquez
  • 2,520
  • 21
  • 13