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

  • SEARCH
  • Home
  • 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 927395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:50:49+00:00 2026-05-15T19:50:49+00:00

I have a tab bar item which shows users favorites in a tableview. I

  • 0

I have a tab bar item which shows users favorites in a tableview. I have another tab bar item which shows a view and allows the user to add a favorite.

Update

this array of favourites gets read from NSUserDefaults in the viewDidLoadMethod of the class which creates and add a favorite.

NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
NSArray *prefs = [def arrayForKey:@"addedQuotes"];  
userAddedQuotes = [[NSMutableArray alloc] initWithArray:prefs];

then this code executes when the user actually adds a favorite

if([text1.text length] && [text2.text length])
{
    NSString *temp = [NSString stringWithFormat:@"%@^%@", 
    text1.text, text2.text];

    [userAdded addObject:temp];

    NSUserDefaults *myDefault = [NSUserDefaults standardUserDefaults];

    [myDefault setObject:userAdded forKey:@"addedFavorites"];

In the tableview class which loads this array from NSUserDefaults to display the values I use the following in the viewWillAppear method.

NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
NSArray *prefs = [def arrayForKey:@"addedFavorites"];   
favorites = [[NSMutableArray alloc] initWithArray:prefs];

At the moment if I add a favorite and then go to the show favorites tab view, it doesnt load the newly added items. only when I exit(press the home button) and start the application again.

How can I get the view to read from the userdefaults again when the tab bar item is selected and the view is shown?

Regards

  • 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-15T19:50:50+00:00Added an answer on May 15, 2026 at 7:50 pm

    Have you tried calling synchronize on it?

    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults synchronize];
    

    Update for comments below – Your table should be using the data from the array that gets the NSUserDefaults loaded into it.

    Your cellForRowAtIndexPath should look something like this (if you are re-using table cells, which you should be)

    ...
    
    if (cell == nil) {
    
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];     
    
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    }
    
    // update cell
    cell.textLabel.text = [myUserDefaultsArray objectAtIndex:indexPath.row];
    NSLog(@"The table data should be %@", [myUserDefaultsArray objectAtIndex:indexPath.row]);
    
    return cell;
    

    You can quickly display the contents of the array to make sure it’s getting updated when the view appears by doing this when the view appears (assuming you’ve already loaded your array)

    int i = 0;
    
    for (i; i<=[myUserDefaultsArray count] - 1; i++) {
    
        NSLog(@"data is %@ for row %d", [myUserDefaultsArray objectAtIndex:i], i);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have 3 main scenes, each with a tab bar item. The first
I have a tab bar controller in the master view of a split view
I have application in which i have create tab-bar dynamically. Now i want to
I have a MainActivity which contains a tab bar with two fragments: MainFragment and
In my iOS application I have a tab bar view with three views. I
I have a tab bar based app. But from one screen the user may
i have an application which uses CoreData/.sqlite to store my data, a tab bar
I have tab bar in which one tab has a UINavigationController that is assigned
I have a tabbar application. And the item of first tab is Navigation Controller.
I have a tab bar along with navigation controller iphone application. Now I need

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.