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 8581525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:04:26+00:00 2026-06-11T21:04:26+00:00

In a view controller (Tab 1), I load from core data like this: –

  • 0

In a view controller (Tab 1), I load from core data like this:

- (void)loadRecordsFromCoreData {

[self.managedObjectContext performBlockAndWait:^{
    NSError *error = nil;
    NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Item"];
    [request setSortDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"order" ascending:YES]]];

    self.items = [self.managedObjectContext executeFetchRequest:request error:&error];

}];
}

I then display the items like this (in viewDidAppear):

- (void)displayItems
{
for(UIView *subview in [self.itemRow subviews]) {
    [subview removeFromSuperview];
}

int xPos = kXItemOffsetIphone;

for (Item *item in self.items) {
    ItemView *itemView = [[ItemView alloc] initWithFrame:CGRectMake(xPos, kYItemOffsetIphone, kItemWidthIphone, kItemHeightIphone) ];

    [itemView layoutWithData:item];

    [self.itemRow addSubview:itemView];

    xPos += kXItemSpacingIphone;
}

}

ItemView is a UIView subclass that displays the image associated with the item, etc.
When I first run the app, all the items are displayed. However, if I click on another Tab, then come back to Tab 1, all my items disappear. The item array is still there, but each item in the array is a “fault”, so nothing gets displayed. Very frustrating. How can I prevent these Items from becoming “faults”?

  • 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-06-11T21:04:27+00:00Added an answer on June 11, 2026 at 9:04 pm

    It sounds like your NSManagedObjectContext is getting deallocated (maybe your view controller is getting unloaded/cleaning itself up when you switch tabs?).

    Behind the scenes, your objects are just proxies for data moving in and out of your SQLite store and between a cache managed by the NSManagedObjectContext. When the context is deallocated, the proxy objects still exist (hence why your array is still filled with objects) however they are unable to ask the deallocated managed object context for data and all of their values revert to faults.

    You have a few options:

    You can pass around a reference to your NSManagedObjectContext as you move between controllers so that you don’t lose it.

    You could re-fetch your data in -viewWillAppear: or another method that you find convenient that is fired every time your view is displayed.

    You could also move your NSManagedObjectContext to a singleton object that exists for the lifetime of the application, however that can become brittle if you’re not careful.

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

Sidebar

Related Questions

info: iOS5, xcode4.3.2, iphone5 Create tab view controller application from xcode template wizard. Following
in controller scrollView.autoresizesSubviews = YES; in viewDidLoad of controller I load view object from
I have a tab bar controller in the master view of a split view
I have a UITableview cell that gets a tally from a core data database.
I'm making a shopping cart. In one tab, I have a table view controller
So I have two view controller that I load on the app delegate when
My view controller is getting a little large for me. I'm implementing five delegate
I have a modal view controller, and I want its navigation bar (I think
I have a table view controller with (among others) a cell that is to
I have a view controller with a scrollview with lots of text boxes, when

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.