I have the problem in changing the toolbar buttons (BarButton Items) depending on whether the user is 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 signed in:
- (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 the buttons available for logout users:
- (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 have tried to do with: [_addButton setTintColor: nil];
with enable/disable
, removeObj
, and even width: 0.01
, but nothing results, 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 (hide / show) depending on the user's status. I also know that you are entering the correct functions because you are printing the correct NSLogs.