Hey guys having trouble with the UI tab controller,
So I have a login screen as my first controller I was wondering if there is a way to lock tab bar items and then unlocking them after login is successful?
At the moment I'm using NSDictionary
to store my username and passwords and an UIAlertView
for alerting whether the login is successful or not, but there really is no point of a login if tabs are accessible without the logging in.
below is my current code for logging in
- (IBAction)loginNow {
if ([[credentialsDictionary objectForKey:usernameField.text]isEqualToString:passwordField.text]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Correct" message:@"You have successfully logged in." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
usernameField.hidden = YES;
passwordField.hidden = YES;
goButton.hidden = YES;
welcomeField.hidden = NO;
nameField.hidden = NO;
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You have entered an incorrect Username or Password" message:@"Please try again." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
}
}
You can use the
tabBarController:shouldSelectViewController:
method inUITabBarControllerDelegate
protocol to returnNO
for tabs which should be inaccessible.Set the relevant object (probably your main view controller) as the delegate of the tab bar, and implement the above method, returning
NO
when the user is not logged in and tries to access a tab which they should not have access to.