I'm having trouble understanding coredata with my uitableview. I have rows being deleted and added all ok.. and the tableview displays them. However, when I then run a query on the number of elements in the database, it returns the number BEFORE I made the delete call.
So an example, I have three rows. I delete two of them. I'd expect my code to return 1 (1 row left) but it returns 3. Do I need to update the record set or something? ie: the delete is made, but not committed or something?
Here's the code I use to query the number of rows... (and the reason I need this is to run operations on the uitableview... so the number of rows in the table should match the number returned from my function)
NSInteger numberofRows = 0;
NSInteger section = 0;
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
numberofRows = [sectionInfo numberOfObjects];
NSLog(@"total rows=%i",numberofRows);
So my method is to
- there are 3 rows in uitableview and the db
- delete selected rows (eg 2)
- reload table view (shows the one remaining row)
- count number of rows in DB (returns 3)
Do I need to refresh the connection or something?? thanks for any help!