Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6169245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:49:33+00:00 2026-05-23T22:49:33+00:00

I have this as my viewDidLoad : – (void)viewDidLoad { [super viewDidLoad]; if (defaults

  • 0

I have this as my viewDidLoad:

- (void)viewDidLoad
{
    [super viewDidLoad];
    if (defaults == [cells objectAtIndex:0])
    {
        NSString * myFile = [[NSBundle mainBundle]pathForResource:@"cells" ofType:@"plist"];
        cells = [[NSMutableArray alloc]initWithContentsOfFile:myFile];
    }
    else
    {
        [defaults stringForKey:@"string1"];
    }
}

And for my viewWillDisappear I have:

-(void)viewWillDisappear:(BOOL)animated
{
    string1 = [cells objectAtIndex:0];
    [defaults setObject:string1 forKey:@"string1"];
}

But I cannot get the data to be saved. Does anyone know what I’m doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:49:33+00:00Added an answer on May 23, 2026 at 10:49 pm

    Are you setting defaults to [NSUserDefaults standardUserDefaults] somewhere? Also, why are you comparing it to the first object in the cells array? Seems strange.

    You’ve otherwise got the idea correct. Make sure the viewWillDisappear method is actually getting called. Also you can call [NSUserDefaults synchronize] to save the changes immediately.

    One last thing, you aren’t doing anything in that else {} block. You need to assign the value of [defaults stringForKey:@"string1"]; to a variable to use it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: - (void)viewDidLoad { [super viewDidLoad]; landscape.image = [UIImage imageNamed:@tenerife1.png]; }
I have this code, where lineaRedToday is an UIImageView: - (void)viewDidLoad { [super viewDidLoad];
I have this code : - (void)viewDidLoad { [super viewDidLoad]; CLLocationCoordinate2D userLocation = CLLocationCoordinate2DMake(48.9793946200,
I have this in my app delegate applicationDidFinishLaunching method: NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
I have this code in my table view controller (and delegate): - (void)tableView:(UITableView *)tableView
I have this situation array = [[NSMutableArray alloc] initWithCapacity:4]; //in viewDidLoad if (index ==
I have this method which gets called from a different class: -(void)artworkInfo:(NSNumber *)pos{ [image
I have the main View controller which adds 2 subviews. - (void)viewDidLoad { [self
I have this code: in viewDidLoad : dateForView = [[NSDate alloc] init]; (dateForView is
I Create a class named DataClass there i have this method +(NSMutableArray*) returnList :(NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.