views:

16

answers:

1

Hi guys,

I've come into a strange situation with my NSFetchedResultsController. I've set it up with a predicate, and the sqlite3 table contains no entries when the app is loaded. Yet my controller sais that the one section in it contains two rows!

One section is fine:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return [[fetchedResultsController sections] count];
}

But two rows???

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
    return [sectionInfo numberOfObjects];
}   

If I instead did

return [[self.fetchedResultsController fetchedObjects] count];

that would be more correct, but why is the first way of doing it wrong? What would make it say two objects?

Cheers

Nik

+1  A: 

What are the objects at index paths [0, 0] and [0, 1]? If it says there are two rows, maybe there are. Just because there's nothing in the database doesn't mean that there aren't objects in a managed object context that haven't been saved yet.

The first way of doing it is the correct way. The second way is wrong if you have multiple sections.

Alex
That's it, there are no objects, I just get an exception if I try to access them
niklassaers