简体   繁体   中英

NSuserdefaults not loading in a tab bar controller, works on uiview

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];
           }
       }

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM