Open mradlmaier opened 10 years ago
I have tried several things:
Modified "didSelectRowAtIndexPath" in SASlideMenuViewController as follows:
NSUserDefaults defaults = [NSUserDefaults standardUserDefaults]; NSString segueId = [self.slideMenuDataSource segueIdForIndexPath:indexPath];
NSLog(@"didSelectRowAtIndexPath"); NSLog(@"login_active: %hhd", [defaults boolForKey:@"login_active"]); NSLog(@"segueId: %@", segueId);
if ([defaults boolForKey:@"login_active"]) { NSLog(@"perform segue"); [self loadContentAtIndexPath:indexPath]; } else if(![defaults boolForKey:@"login_active"] && ![segueId isEqualToString:@"ausloggen"]){ NSLog(@"perform logout"); [self loadContentAtIndexPath:indexPath]; } else if (![defaults boolForKey:@"login_active"] && [segueId isEqualToString:@"ausloggen"]){ NSLog(@"DONT perform logout"); return; }
This had no effect neither. The method is always called, but either it always causes the segues or always doesn't cause segue no matter what the value of [defaults boolForKey:@"login_active"] is...
Have you tried to use the UITableViewDelegate method:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
If you return nil tha cell should not be selectable and the segue should not be fired.
I will try that, thanks Cheers, Michael
Von meinem iPhone gesendet
Am 15.06.2014 um 12:57 schrieb stefanoa notifications@github.com:
Have you tried to use the UITableViewDelegate method:
- (NSIndexPath )tableView:(UITableView )tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath If you return nil tha cell should not be selectable and the segue should not be fired.
— Reply to this email directly or view it on GitHub.
I implemented it like you suggested:
But: If I disable the logout, terminate the app, restart the app, the app will correctly start with out displaying the login controller. Then I enable the logout in the settings controller, and then try to logout, it does not perform the segue as it should, although the logs show, that the user defaults are correctly set, and the indexPath is the one of the logout cell, and even the respective if - branch is executed. Note: I am using an unwind segue for the logout, because I want that the stack of view controllers is correctly cleared (I fear memory leaking/memory growth unlimited).
The idea is that I have a login to secure sensitive data stored in the app, but that the user can opt out of logging in, if he chooses, too.
If you have a simple project that I can test I will have a look at it.
This project is not simple, it has many View Controllers. I would have to setup an example.
But what I have found, is, if I use a normal segue instead of an unwind segue, it works.
My theory is, that unwind segues can only segue to previously presented/executed view controllers, not to any view controller in the storyboards. At least that is my observation:
--> User logins and out --> this works
--> User logins, disables login, closes app, opens app, (no login view controller presented), enables login --> unwind segue doesn't work --> User logins, disables login, brings app into background, brings app into foreground again, enables login --> unwind segue works
Obviously unwind segue to the login vc only works, if the login vc was previously open.
I wanted to use unwind segues, because my app has many view controllers, and I wanted that, when the user logs out, memory occupied by a huge stack of controllers is freed ;-)
Is it possible to enable/disable a menuitem programmatically depending on some value? If yes, how?