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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:38:09+00:00 2026-05-25T10:38:09+00:00

I have 2 views that contain a UITableView each. They are both displayed at

  • 0

I have 2 views that contain a UITableView each. They are both displayed at the same time, side by side, on an iPad.

I am using Core Data for all data. Both tables need to be edited (rows added, deleted, etc), so I’d like to use a NSFetchedResultsController in each view to handle all this for me.

The contents of the second table depend on what is selected in the first table. So, when selecting an item in the first table, that object is passed to the view with the second table (so I do already have access to the data that should go into the second table), but I’d like to try to use all the built-in handling of the NSFRC if possible.

The model is along the lines of: University (uniID, uniName, students) and Student (stuID, stuName, university). So the relationship is: University <–>> Student.

I’m using the following code in the NSFRC, but it’s returning 0 results:

- (NSFetchedResultsController *)fetchedResultsController {

if (fetchedResultsController != nil) {
    return fetchedResultsController;
}

NSManagedObjectContext *context = appDelegate.managedObjectContext;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Student" inManagedObjectContext:context];
[fetchRequest setEntity:entity];

NSSortDescriptor *sort = [[NSSortDescriptor alloc]initWithKey:@"stuName" ascending:YES];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];

[fetchRequest setFetchBatchSize:20];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"university == %@",self.selectedUniversity];
[fetchRequest setPredicate:predicate];

NSFetchedResultsController *theFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:context sectionNameKeyPath:nil cacheName:nil];

self.fetchedResultsController = theFetchedResultsController;
fetchedResultsController.delegate = self;

[sort release];
[fetchRequest release];
[theFetchedResultsController release];

return fetchedResultsController;    

}

I would be most grateful if someone could at least point me in the right direction…

  • 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-25T10:38:10+00:00Added an answer on May 25, 2026 at 10:38 am

    Ok, so I solved the issue. The NSFRC wasn’t being updated when the predicate term needed to change (i.e. a University had been selected), of course, because of:

    if (fetchedResultsController != nil) {
        return fetchedResultsController;
    }
    

    Having the NSFRC recreated every time it’s called (by removing the above code) doesn’t work either, because the fetch needs to be executed after it’s been created, which can’t happen just before numberOfRowsInSection is called (as this method calls, and therefore recreates, the NSFRC).

    So, I added a BOOL to the view called newFetchRequired which is set to YES every time a new University is selected. In the NSFRC, the above code should be changed to:

    if (fetchedResultsController != nil && !newFetchRequired) {
            return fetchedResultsController;
        }
    newFetchRequired = NO;
    

    The fetch is then performed correctly (which calls and recreates the NSFRC):

    [self.fetchedResultsController performFetch:&error];
    

    I hope this helps anyone in a similar situation.

    Thanks to Ashley for the alternative suggestion.

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

Sidebar

Related Questions

I have a UITableView whose cells contain UITableViews that are rotated 90° (so they
I have one (razor) page that contain 5 different partial views. Each partial view
I have two tabbar items(views) that use the same data, whats the best solution
I have a list view full of items that contain multiple widgets each such
I have a UITableView with cells that contain a UISwitch control. It's similar to
Here is my scenario. I have 3 out of 4 tab views that contain
I have a view using a master page that contains some javascript that needs
I have two views that I would like to combine into one. The first
All of a sudden in this MVC site I have no views that can
In one of my iPhone projects, I have three views that you can move

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.