Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabling temporarily the slidemenu or selected menuitems #113

Open
mradlmaier opened this issue Feb 13, 2014 · 8 comments
Open

Disabling temporarily the slidemenu or selected menuitems #113

mradlmaier opened this issue Feb 13, 2014 · 8 comments

Comments

@mradlmaier
Copy link

I am using your SASlideMenu with storyboards, as you know.

I have a button on my first view controller, which segues to a view controller, where the user can create his profile. I need to ensure that before a user moves to one of the view controllers in the slide menu, the user first creates a profile. I think that means to disable the SASlideMenu until the profile is created.

How can I do that?

Better than completely disabling the SASlideMenu would be to disable selectively menuitems and enable them again, once the user created his profile.

How can I do that?

@mradlmaier
Copy link
Author

I read through issue 76 and followed that instructions. Now my SASlideMenu is disabled until the user creates a first profile, which is nice.
When the first profile is created, the menu is enabled.

However, if the user deletes his profile, the menu is NOT disabled again.

Here is my code in SASlideMenuViewController:

-(Boolean) disablePanGestureForIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row == 10) {
// disable for MRPatientenTableViewController
return YES;
}
if (indexPath.row == 13) {
// disable for MRKrankenkassenTableViewController
return YES;
}
if (indexPath.row == 1) {
// disable for MRFreitexteTableViewController
return YES;
}
if (indexPath.row == 0) {
// disable/enable depending if there are patients and 1 is selected as currentPatient
if ([self shouldEnableSASlideMenu]) {
return NO;
} else {
return YES;
}
}
return NO;
}

-(void) configureMenuButton:(UIButton *)menuButton{
menuButton.frame = CGRectMake(0, 0, 40, 29);
[menuButton setImage:[UIImage imageNamed:@"menuicon"] forState:UIControlStateNormal];
_menuButton = menuButton;
}

-(void) prepareForSwitchToContentViewController:(UINavigationController )content{
UIViewController
controller = [content.viewControllers objectAtIndex:0];

if ([controller isKindOfClass:[LightViewController class]]) {
    LightViewController* lightViewController = (LightViewController*)controller;
    lightViewController.menuViewController = self;
} else if ([controller isKindOfClass:[MRTestViewController class]]){
    MRTestViewController *testViewController = (MRTestViewController *)controller;
    testViewController.menuViewController = self;
} else if ([controller isKindOfClass:[MRHomeViewController class]]){
    MRHomeViewController *homeViewController = (MRHomeViewController *)controller;
    homeViewController.menuViewController = self;
    homeViewController.menuButton = _menuButton;

    if ([self shouldEnableSASlideMenu]) {
        [_menuButton setEnabled:YES];
    } else {
        [_menuButton setEnabled:NO];
    }

}

}

In my MRHomeViewController (That is the main view controller) in viewWillAppear:

if ([self shouldEnableSASlideMenu]) {
[_menuButton setEnabled:YES];
} else {
[_menuButton setEnabled:NO];
}

And of course I have passed the menuButton to my MRHomeViewController...

@stefanoa
Copy link
Owner

Hi Michael,

If I understand correctly, you need something like what is described in #84. The idea is that you present the SASlideMenuViewController only when logged in with your profile and when you logout you are sent back to the login/signup views.

@mradlmaier
Copy link
Author

No Stefano,
Not exactly. A user can have several profiles, but he should not be allowed to open any scene (from the slidemenu), if he has not selected a profile yet. He can select a profile on the main screen, that's why I really want to have this enable/disable SASlideMenu conditionally on the main screen.
The login/signup thingie will be implemented in the future to enable the user to "lock" the app and prevent unauthorised usage of the app.
I managed to have the SASlideMenu disabled on launch on the main screen and enable it once the user has chosen a profile, but I can't disable it....?

Actually I would love to see a feature like this:

  • To be able to en/disable any Menuitem from anywhere in the app...

@stefanoa
Copy link
Owner

What I Understand is that you want the menu to be active only when the user selected a profile and when the profile is selected the menu is presented again.
To do that I will create a ProfileSelectorViewController that will have a method:

\\ you should add parameters as needed 
-(void) profileSelected;

The method will be called when the new profile is selected. The implementation will look like:

-(void) profileSelected{
\\ other stuff you need 

   UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
   // the segue with id "Main" is the segue with the SASlideRootViewController 
   UIViewController* controller = [storyboard instantiateViewControllerWithIdentifier:@"Main"];
   [self presentViewController:controller animated:YES completion:^{
        MyAppDelegate* app = (MyAppDelegate*)[[UIApplication sharedApplication] delegate];
        [app.window setRootViewController:controller];
    }];
}

Than in the SASlideMenuViewController implementation there will be a menu item that will call

-(void) selectProfile;

The selectProfile implementation and didSelectRowAtIndexPeth implementation will be:

-(void) selectProfile{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    \\ The ProfileSelector is the View Controller that select the profile and will have segueId = "ProfileSelector"
    UIViewController* controller = [storyboard instantiateViewControllerWithIdentifier:@"ProfileSelector"];
    [self presentViewController:controller animated:YES completion:^{
       MyAppDelegate* app = (MyAppDelegate*)[[UIApplication sharedApplication] delegate];
       [app.window setRootViewController:controller];     
    }];
}

\\ here we intercept the menu selection to trigger the select profile
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 && indexPath.row == 13) {
        //Select Profile Menu Item
       [self selectProfile];        
    }else{
        [super tableView:tableView didSelectRowAtIndexPath:indexPath];
    }
}

@mradlmaier
Copy link
Author

Ok, tx. I will try that...

@mradlmaier
Copy link
Author

I should clarify my app scenes a bit:

There is a ViewController A, which is the scene presented when the user starts the app.
There is a collection view, which displays all existing profiles (if any) and 1 UICollectionViewCell which, when selected, will open the profile view controller (B), in which the user can create a profile.

When there are NO existing profiles, the menu button should be disabled.
When the user creates the first profile, the menu button should become enabled.

There is another view controller C, which is accessible through the slide menu, and which is a table view controller displaying all existing profiles. The user can edit an existing profile by clicking a table view cell which will open profile view controller B. He can click on a navigation bar button on the right "+" which will open the view controller B in modal mode to add a new profile.

So, in this table view controller C, the user can delete profiles, too. So it can happen that the user deletes all profiles, and if this happens, the menu button should be disabled, to prevent the user from navigating away from that scene, until he creates a new profile by tapping "+" and opening a profile view controller C.

This is not exactly the scenario you describe above.

I manage to have the menu button enabled and disabled by storing a reference to it, either in the SASlideMenuViewController or the respective view controller, however, when the user would navigate A --> B --> A --> C... etc. but if he ever selects a different view controller in the slide menu, the reference somehow is lost.... I was coding something on the lines of issue 76 #76 but the refernce always is lost once the user slides the menu and selects any other scene, and goes back to C. Then the reference to the button in C is lost.

I need a way to enable/disable the slidemenu, after any user action/navigation, in any view controller, based on some criteria...
Any ideas?

@stefanoa
Copy link
Owner

There is a menu button on each content view thus you have to disable/enable all of them and I think is the wrong way of doing it.

@mradlmaier
Copy link
Author

I understand.

I don`t see a way to disable/enable all of them from anywhere, because I don’t know how I can obtain references to each of them?

Is there a way to obtain references to each of them anytime, anywhere. From what I gathered, I can only obtain a reference to the last used content, so when a user navigates to somewhere else, I don`t have a reference to the buttons on the other content view controller…?

On 20 Feb 2014, at 11:15, stefanoa [email protected] wrote:

There is a menu button on each content view thus you have to disable/enable all of them and I think is the wrong way of doing it.


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants