Can I include a NSUserDefault password test in AppDelegate to load a loginView?
Posted
by Michael Robinson
on Stack Overflow
See other posts from Stack Overflow
or by Michael Robinson
Published on 2010-06-08T00:23:36Z
Indexed on
2010/06/08
0:32 UTC
Read the original article
Hit count: 463
I have a name and password in NSUserDefaults for login. I want to place a test in my AppDelegate.m class to test for presence and load a login/signup loginView.xib modally if there is no password or name stored in the app.
Here is the pulling of the defaults:
-(void)refreshFields {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
usernameLabel.text = [defaults objectForKey:kUsernameKey];
passwordLabel.text = [defaults objectForKey:kPasswordKey];
Here is the tabcontroller loading part: - (void)applicationDidFinishLaunching:(UIApplication *)application {
firstTab = [[FirstTab alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *firstNavigationController = [[UINavigationController alloc] initWithRootViewController:firstTab];
[firstTab release];
secondTab = // EDITED FOR SPACE
thirdTab = // EDITED FOR SPACE
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:firstNavigationController, secondNavigationController, thirdNavigationController, nil];
[window addSubview:tabBarController.view];
[firstNavigationController release];
[secondNavigationController release];
[thirdNavigationController release];
[self logout];
[window makeKeyAndVisible];
Here is where the loginView.xib loads automatically:
- (void)logout {
loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:nil];
UINavigationController *loginNavigationController = [[UINavigationController alloc] initWithRootViewController:loginViewController];
[loginViewController release];
[tabBarController presentModalViewController:loginNavigationController animated:YES];
[loginNavigationController release];
}
I want to replace the above autoload with a test similar to below (that works) using IF-ELSE
- (void)logout {
if ([usernameLabel.text length] == 0 || [passwordLabel.text length] == 0)
{
loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:nil];
UINavigationController *loginNavigationController = [[UINavigationController alloc] initWithRootViewController:loginViewController];
[loginViewController release];
[tabBarController presentModalViewController:loginNavigationController animated:YES];
[loginNavigationController release];
}else
{
[window addSubview:tabBarController.view];}
Thanks in advance, I'm totally lost on this.
© Stack Overflow or respective owner