In my iOS app there is a view controller with six buttons. The buttons work as main menu of the app.
If the user is not logged in, must show only :
If the user is logged in, must show only:
At a new fresh app start, the view controller shows the correct buttons. It takes into account if the user is logged in or not. The app uses NSDefaults to keep the session info.
But then, if the user logs out or logs in, the view controller shows the six buttons....
I need your help to know on which method should I put the condition that determines if the user is logged in show the buttons ACTION C, ACTION D and ACTION E, and if the user is not logged in show the buttons LOG IN, ACTION A and ACTION B. I have tried in methods viewDidLoad, viewWillAppear and viewDidAppear, but no success.
It is a view controller that works as the rear part of a SWRevealViewController implementation.
Thank you.
Dont use drawers...
You need to keep track of the state of the login in your app and create/reload the view as needed.
- (void)setupButtons
{
BOOL isLoggedIn = [[NSUserDefaults standardUserDefaults] boolForKey:@"IsLoggedIn"];
loginButton.setHidden = isLoggedIn;
buttonA.setHidden = isLoggedIn;
buttonB.setHidden = isLoggedIn;
buttonC.setHidden = !isLoggedIn;
buttonD.setHidden = !isLoggedIn;
buttonE.setHidden = !isLoggedIn;
}
call this method in -viewDidAppear
of your view controller. And also after NSUserdefaults
is set on login or logout and if this viewController is active.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.