I am creating app for jobsite. It will display login page first. when we enter username and password webservice will return userid as response. with this user id we can get jobs.
I want to put jobs screen first and check if user id is null then open loginview. if it is not null then load jobs in tableview. I used Nsuserdefaults to save response when user first enter username password. Every thing is working fine. but userdefault key is showing null in console but my condition is loading output also.. this is strange,.
my code is
-(void)CheckCond{
NSUserDefaults* storeData = [NSUserDefaults standardUserDefaults];
NSLog(@"Value for userdefault %@",[storeData objectForKey:@"userId"]);
NSString *responseValue = [storeData objectForKey:@"userId"];
NSLog(@"first REsponse value :%@",responseValue);
if ([responseValue isEqualToString:@""]) {
[self LoginLogout];
}
else
{
NSLog(@"self.userId %@",self.userId);
NSUserDefaults* storeData = [NSUserDefaults standardUserDefaults];
[storeData setObject:self.userId forKey:@"userId"];
NSLog(@"%@",[storeData objectForKey:@"userId"]);
[self loadOutput];
}
}
Console output for first time login is
2011-09-09 13:21:29.438 ITClassifiedUniversal[2718:207] first REsponse
value :(null) 2011-09-09 13:21:29.438 ITClassifiedUniversal[2718:207]
self.userId 77533 2011-09-09 13:21:29.438
ITClassifiedUniversal[2718:207] 77533
After quitting app and restarting console output is :
2011-09-09 13:21:42.044 ITClassifiedUniversal[2731:207] Value for
userdefault (null) 2011-09-09 13:21:42.045
ITClassifiedUniversal[2731:207] first REsponse value :(null)
2011-09-09 13:21:42.045 ITClassifiedUniversal[2731:207] self.userId
(null) 2011-09-09 13:21:42.045 ITClassifiedUniversal[2731:207] (null)
AS above output shows NSUserdefault for userid is null?? whts the problem ?
This user id is coming from login view
// Create and set up job view controller.
jobView = [[JobViewController alloc] initWithNibName:@"JobView" bundle:nil];
jobView.userId = self.response;
// Create a nav controller with job view as its root controller.
UINavigationController *jobViewNavController = [[UINavigationController alloc] initWithRootViewController:jobView];
// Present the job view nav controller.
[self presentModalViewController:jobViewNavController animated:YES];
[jobView release];
[jobViewNavController release];
1 Answer