I am having a strange problem. When I add a record to entities i.e. core data from certain screens, the table view instead of showing the new record, repeats the previous record.
It always happens with some entities and screens, i.e. if I add records, 1,2,3 etc. it will display 1,1,1. With other screens and entities that use identical code, it sometimes happens, usually after about the eight through tenth record.
In these cases, if I add records named 1,2,3…10, it will display 1,2,3,4,5,6,7,8,8,8,8,8,8 etc.
Has anyone ever encountered this strange/spooky behavior? Why would it think that the new record is the same as the previous record either right away or at some point i.e. when the number of records hits 8 or so?
Note, it saves fine in core data as when I close the simulator and rebuild, it shows the right records.
The delegate pattern also seems to be working—somewhat—as it shows a new record when one is added, only it shows a copy of the last record and then the record on which it got stuck, i.e. 8,8,8 etc.
Thanks for any suggestions. This has been driving me crazy for a week now.
Am posting without code as SO will not accept the code I posted for some reason... Happy to post any code requested.
Edit:
#pragma mark - Table view data source
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"Cell"];
Lists *list = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = list.listname;
cell.detailTextLabel.text = list.list;
return cell;
}
In response to Duncan:
Apple's documentation states:
"A delegate must implement at least one of the change tracking delegate methods in order for change tracking to be enabled. Providing an empty implementation of controllerDidChangeContent: is sufficient."
My code includes:
#pragma mark - NSFetchedResultsControllerDelegate
-(void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
//change
}
I know there is a more verbose method with will change content and did change content with a switch statement for different cases but the documentation says that is not necessary. (I also tried it and it did not fix problem.) I declare the list file as the delegate in the header with:
@interface ListsVC : UITableViewController<UITableViewDataSource, UITableViewDelegate,NSFetchedResultsControllerDelegate>