0
I have the problem in changing Toolbar buttons (Barbutton Items) depending on whether you are logged in or not.
Tableviewcontroller:
- (void)viewDidLoad {
[super viewDidLoad];
User *userObj = [[User alloc] init];
if([userObj userAuthenticated]){
[self showLoginButtons];
}
else{
[self showLogoutButtons];
}
[self.tableView reloadData];
}
Show buttons when login:
- (void) showLoginButtons{
NSArray *toolbarButtonsLogin = [NSMutableArray arrayWithObjects: _addButton, _editButton, _flexibleSpace, _logOutButton, nil];
//[_myToolbar setItems: toolbarButtonsLogin animated:NO]; // com esta linha também não resulta
[_myToolbar setItems: toolbarButtonsLogin animated:NO];
NSLog(@"loginBttons");
}
Show buttons available for users logout:
- (void) showLogoutButtons{
NSArray *toolbarButtonsLogin = [NSMutableArray arrayWithObjects: _flexibleSpace, _logInButton, nil];
//[_myToolbar setItems: toolbarButtonsLogin animated:NO]; // com esta linha também não resulta
[_myToolbar setItems: toolbarButtonsLogin animated:NO];
NSLog(@"logoutBttons");
}
Logout:
- (IBAction)LogOut:(UIBarButtonItem *)sender {
User *userObj = [[User alloc] init];
[userObj logout];
[self showLogoutButtons];
}
Loginviewcontroller:
- (IBAction)LogIn:(UIButton *)sender {
TableViewController *resetButtons = [[TableViewController alloc] init];
if([userObj userAuthenticated]) {
[resetButtons showLoginButtons];
[self.view setNeedsDisplay];
[self dismissLoginAndShowProfile];
}
}
I’ve tried to do with: [_addButton setTintColor: nil];
with enable/disable
, removeObj
, and even put the width: 0.01
, but nothing works, just strange behavior for no apparent reason. The login/logout is working properly without any problems, only the buttons do not do what is supposed to (Hide/show) depending on the status of the user. I also know that you are entering the correct functions because you are printing the correct Nslog.
your logic wouldn’t be the other way around? If the user is logged in, display the logout buttons and vice versa?
– Lucas Eduardo
This is correct. When I am logged in the add, Edit and logout button appears and when I am not only the login button appears.
– Clara Frazão