Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't fetch number of cells in tableView
    text
    copied!<p>I have a main tableViewController, touch a button self.navigation will push addItem viewController, click save self.navigation with pop the add VC, then we're back on the main one, I successfully add and save, also fetch, but when it comes to fetching number of cells, number returns 0, heres the method</p> <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { id &lt;NSFetchedResultsSectionInfo&gt; secInfo = [[self.fetchedResultsController sections] objectAtIndex:section]; NSLog(@"No. of cells determined: %lu", (unsigned long)[secInfo numberOfObjects]); return[secInfo numberOfObjects]; } </code></pre> <p>NSLog gives me 0, whats the problem, this gave me headache.</p> <p>Here's the fetch request:</p> <pre><code>- (NSFetchedResultsController*) fetchedResultsController { // Fetch Request NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Goal" inManagedObjectContext:self.managedObjectContext]; [fetchRequest setEntity:entity]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:NO]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; [fetchRequest setSortDescriptors:sortDescriptors]; // setting _fethcedResultsController _fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil]; // setting _fetchedResultsController to self _fetchedResultsController.delegate = self; // for the tableview updating thing // Thats it return _fetchedResultsController; } </code></pre> <p>Please note that when I run a check for items, it's not nil:</p> <pre><code>// fetching all items to check how many of them exists NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; [fetchRequest setEntity: [NSEntityDescription entityForName:@"Goal" inManagedObjectContext:self.managedObjectContext]]; NSManagedObjectContext *moc = self.managedObjectContext; NSError *fetchError = nil; NSArray *goals = [moc executeFetchRequest:fetchRequest error:&amp;fetchError]; NSLog(@"No. of goals: %lu", (unsigned long)[goals count]); // end of check for items </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload