views:

33

answers:

1

I have a problem getting the NSUserDefaults to pull out on a tab/nav/tableview controller page, I've put the same code on a loginpage and the app will pull the objects for keys perfectly. I had this working when I had programmatically created the tabs and navs but now it's not working. The loginViewController is not in the tab stack, is that the reason it works?

-(void)refreshFields {
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        usernameLabel.text = [defaults objectForKey:kUsernameKey];
        passwordLabel.text = [defaults objectForKey:kPasswordKey];
    }

- (void)viewDidAppear:(BOOL)animated {
        [self refreshFields];
        [super viewDidAppear:animated];

      if ([usernameLabel.text length] == 0|| [passwordLabel.text length] == 0)
          {

             UINavigationController *loginNavigationController = [[UINavigationController alloc] initWithRootViewController:loginViewController];
             [loginViewController release];

            [self.navigationController presentModalViewController:loginNavigationController animated:NO];
            [loginNavigationController release];

           }
      else 
           {
             [[self tableView ]reloadData];
           }
       }
+2  A: 

Your usernameLabel and passwordLabel outlets aren't set. Verify by putting a breakpoint in refreshFields.

Steven Fisher
It's a tableview, and I'm using IB, where would I set the outlets from the File's Owner?
Michael Robinson
I made a view for the outlets, I've not seen by anyone but it's working perfectly. Thanks,
Michael Robinson